Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clone_from/push_to: Improve consistency between actions. #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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=''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: the quote types should match the rest of the file. It looks like in most cases we're doing ". Other than that this looks good to me.

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