Skip to content

Fix for workflow failing when there is nothing to commit #3

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

Merged
merged 4 commits into from
Apr 28, 2022
Merged
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
39 changes: 25 additions & 14 deletions .github/workflows/test-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,11 @@ name: Run tests, Tag release
on:
push:
branches:
# explicit deny all here to make sure there isnt a commit loop
- '!*'
- main
- fix/*

jobs:
create_tag:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: run_tests
steps:
- name: Checkout
uses: actions/checkout@v2

- name: check if tag already exists
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0

- name: create tag
run: git config --global user.email "${{ github.actor }}" && git config --global user.name "${{ github.actor }}" && git tag -a -m "$(cat VERSION)" $(cat VERSION) && git push --follow-tags
run_tests:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -98,3 +84,28 @@ jobs:
destination_branch: commit_message_test
deploy_key: ${{ secrets.DEPLOY_KEY }}
commit_message: testing a custom commit message (${{ github.sha }})

- name: test workflow doesnt fail when there is nothing to commit
uses: ./
with:
source: tmp.txt
destination_repo: leigholiver/commit-with-deploy-key
destination_branch: commit_message_test
deploy_key: ${{ secrets.DEPLOY_KEY }}
commit_message: testing a custom commit message (${{ github.sha }})


# If the tests are successful, and we've merged to main, create a tag
create_tag:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: run_tests
steps:
- name: Checkout
uses: actions/checkout@v2

- name: check if tag already exists
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0

- name: create tag
run: git config --global user.email "${{ github.actor }}" && git config --global user.name "${{ github.actor }}" && git tag -a -m "$(cat VERSION)" $(cat VERSION) && git push --follow-tags
49 changes: 19 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Commit with deploy key
Action to commit a file/directory to another repo using a deploy key.
Action to commit a file or directory to another repo using a deploy key.

## Example usage
## Usage
* Create an SSH key pair to use for the commits
* Add the public key to your destination repo as a deploy key with push access
* Add the public key to your destination repo as a deploy key with write access
* Add the private key to your source repo as a secret

* Add this action to your workflow:
```yaml
uses: leigholiver/commit-with-deploy-key@v1.0.2
uses: leigholiver/commit-with-deploy-key@v1.0.3
with:
source: build_output
destination_folder: dist
Expand All @@ -16,30 +16,19 @@ with:
```

## Inputs
### `source`
**Required** The file/directory to commit

### `deploy_key`
**Required** Private SSH key to use for the commit. The public key must be added to the destination repostitory as a deploy key, with push access

### `destination_repo`
**Required** Git repository to push changes to

### `destination_folder`
Directory in the destination repo to push changes to (default `.`)

### `destination_branch`
Branch in destination repo to push changes to (default `main`)

### `delete_destination`
Delete destination directory contents before copy? (default `false`)

### `git_username`/`git_email`
Github user to use for the commit (default: `${{ github.actor }}`)

### `commit_message`
Commit message (default `<action name> from <commit hash>`)
| Name | Required | Default | Description |
|--------------------- |--------- |----------------------------------- |---------------------------------------------------------|
| `source` | `true` | | The file/directory to commit |
| `deploy_key` | `true` | | Private SSH key to use for the commit. The public key must be added to the destination repostitory as a deploy key, with push access |
| `destination_repo` | `true` | | Git repository to push changes to |
| `destination_folder` | `false` | `.` | Directory in the destination repo to push changes to |
| `destination_branch` | `false` | `main` | Branch in destination repo to push changes to |
| `delete_destination` | `false` | `false` | Delete destination directory contents before copy? |
| `git_username` | `false` | `${{ github.actor }}` | Github user to use for the commit |
| `git_email` | `false` | `${{ github.actor }}` | Github user to use for the commit |
| `commit_message` | `false` | `<action name> from <commit hash>` | Commit message |

## Outputs
### `commit_hash`
SHA hash of the generated commit
| Name | Description |
|---------------|----------------------------------|
| `commit_hash` | SHA hash of the generated commit |
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.2
v1.0.3
4 changes: 2 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ elif [ -d $CALLING_DIR/$INPUT_SOURCE ]; then
cp -a $CALLING_DIR/$INPUT_SOURCE/* .
fi

# commit and push
# create the commit
git add .
git commit -m "${INPUT_COMMIT_MESSAGE}"
git commit -m "${INPUT_COMMIT_MESSAGE}" || echo
GIT_SSH_COMMAND=$GIT_SSH git push -u origin $INPUT_DESTINATION_BRANCH

# output the commit hash
Expand Down