Skip to content

Commit

Permalink
clone_from/push_to: Improve consistency between actions.
Browse files Browse the repository at this point in the history
Make consistent the following;
 * Wording in output.
 * Checking of inputs.
 * Git environment variables.
 * Quoting of command line arguments.
 * How optional arguments are given to git using `GIT_ARGS`.

Signed-off-by: Tim 'mithro' Ansell <[email protected]>
  • Loading branch information
mithro committed May 21, 2021
1 parent a846cbc commit e6ac8ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
29 changes: 16 additions & 13 deletions clone_from/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Clone a GitHub repository.
name: Clone from a GitHub repository.

inputs:
owner:
Expand All @@ -19,18 +19,20 @@ runs:

steps:

- name: Cloning ${{ inputs.slug }}
- name: Cloning ${{ inputs.branch }} from ${{ inputs.owner }}/${{ inputs.repo }}
shell: bash
env:
GH_TOKEN: ${{ github.token }}
SLUG: ${{ inputs.owner }}/${{ inputs.repo }}
run: |
export GIT_TERMINAL_PROMPT=0
export GCM_INTERACTIVE=Never
if [[ -z "${{ inputs.owner }}" ]]; then echo "Missing owner value!"; exit 1; fi
if [[ -z "${{ inputs.repo }}" ]]; then echo "Missing repo value!"; exit 1; fi
if [[ -z "${{ inputs.branch }}" ]]; then echo "Missing branch value!"; exit 1; fi
if [[ -z "${{ inputs.checkout }}" ]]; then echo "Missing checkout value!"; exit 1; fi
cd ..
time rm -rf ${{ inputs.repo }}
time rm -rf "${{ inputs.repo }}"
git config --global gc.auto 0
git config --global fetch.recurseSubmodules false
Expand All @@ -40,22 +42,23 @@ runs:
cat ~/.gitconfig
# Checkout if needed
if [[ '${{ inputs.checkout }}' != 'true' ]]; then
GIT_CLONE_ARGS="--no-checkout"
export GIT_ARGS=''
if [[ "x${{ inputs.checkout }}" != 'xtrue' ]]; then
export GIT_ARGS="--no-checkout"
fi
# Clone a blobless repository and don't bother checking it out.
# Clone a blobless repository.
set -x
time git clone \
$GIT_CLONE_ARGS \
$GIT_ARGS \
--filter=blob:none \
--no-tags \
--origin upstream \
--branch ${{ inputs.branch }} \
--branch "${{ inputs.branch }}" \
--verbose \
https://token:${GH_TOKEN}@github.com/${SLUG}.git
"https://token:${{ github.token }}@github.com/${{ inputs.owner }}/${{ inputs.repo }}.git"
set +x
# Enter cloned repository
cd ${{ inputs.repo }}
cd "${{ inputs.repo }}"
ls -l .
22 changes: 16 additions & 6 deletions push_to/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Push to repository.
name: Push to a GitHub repository.

inputs:
owner:
description: GitHub username who owns the repository.
default: ${{ github.event.repository.owner.name }}
default: ${{ github.event.repository.owner.login }}
repo:
description: GitHub repo name.
default: ${{ github.event.repository.name }}
Expand All @@ -22,21 +22,31 @@ runs:

steps:

- name: Pushing ${{ inputs.branch }} to ${{ inputs.slug }}
- name: Pushing ${{ inputs.branch }} from ${{ inputs.owner }}/${{ inputs.repo }}
shell: bash
run: |
export GIT_TERMINAL_PROMPT=0
export GCM_INTERACTIVE=Never
if [[ -z "${{ inputs.owner }}" ]]; then echo "Missing owner value!"; exit 1; fi
if [[ -z "${{ inputs.repo }}" ]]; then echo "Missing repo value!"; exit 1; fi
if [[ -z "${{ inputs.branch }}" ]]; then echo "Missing branch value!"; exit 1; fi
if [[ -z "${{ inputs.force }}" ]]; then echo "Missing force value!"; exit 1; fi
if [[ -z "${{ inputs.deployToken }}" ]]; then echo "Missing deployToken value!"; exit 1; fi
# Figure out if we should do a force push
export GIT_ARGS=''
if [[ x${{ inputs.force }} = 'xtrue' ]]; then
if [[ "x${{ inputs.force }}" = 'xtrue' ]]; then
export GIT_ARGS=--force
fi
# Add local repository and push to it.
git remote add origin https://token:${{ inputs.deployToken }}@github.com/${{ inputs.owner }}/${{ inputs.repo }}.git
git push $GIT_ARGS origin --verbose ${{ inputs.branch }}
git remote add origin "https://token:${{ inputs.deployToken }}@github.com/${{ inputs.owner }}/${{ inputs.repo }}.git"
set -x
time git push \
$GIT_ARGS \
origin \
--verbose \
"${{ inputs.branch }}"
set +x

0 comments on commit e6ac8ab

Please sign in to comment.