Skip to content

Commit 9562ffd

Browse files
authored
Fix for workflow failing when there is nothing to commit (#3)
* Add test case for workflow failure on nothing to commit * Check for new commit before trying to push * Alternative fix with a better understanding of whats going on... * tidy up
1 parent af931f6 commit 9562ffd

File tree

4 files changed

+47
-47
lines changed

4 files changed

+47
-47
lines changed

.github/workflows/test-tag.yml

+25-14
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,11 @@ name: Run tests, Tag release
33
on:
44
push:
55
branches:
6-
# explicit deny all here to make sure there isnt a commit loop
7-
- '!*'
86
- main
97
- fix/*
108

119
jobs:
12-
create_tag:
13-
runs-on: ubuntu-latest
14-
if: github.ref == 'refs/heads/main'
15-
needs: run_tests
16-
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v2
19-
20-
- name: check if tag already exists
21-
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0
2210

23-
- name: create tag
24-
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
2511
run_tests:
2612
runs-on: ubuntu-latest
2713
steps:
@@ -98,3 +84,28 @@ jobs:
9884
destination_branch: commit_message_test
9985
deploy_key: ${{ secrets.DEPLOY_KEY }}
10086
commit_message: testing a custom commit message (${{ github.sha }})
87+
88+
- name: test workflow doesnt fail when there is nothing to commit
89+
uses: ./
90+
with:
91+
source: tmp.txt
92+
destination_repo: leigholiver/commit-with-deploy-key
93+
destination_branch: commit_message_test
94+
deploy_key: ${{ secrets.DEPLOY_KEY }}
95+
commit_message: testing a custom commit message (${{ github.sha }})
96+
97+
98+
# If the tests are successful, and we've merged to main, create a tag
99+
create_tag:
100+
runs-on: ubuntu-latest
101+
if: github.ref == 'refs/heads/main'
102+
needs: run_tests
103+
steps:
104+
- name: Checkout
105+
uses: actions/checkout@v2
106+
107+
- name: check if tag already exists
108+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* && git rev-parse "$(cat VERSION)" >/dev/null 2>&1 && exit 1 || exit 0
109+
110+
- name: create tag
111+
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

README.md

+19-30
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Commit with deploy key
2-
Action to commit a file/directory to another repo using a deploy key.
2+
Action to commit a file or directory to another repo using a deploy key.
33

4-
## Example usage
4+
## Usage
55
* Create an SSH key pair to use for the commits
6-
* Add the public key to your destination repo as a deploy key with push access
6+
* Add the public key to your destination repo as a deploy key with write access
77
* Add the private key to your source repo as a secret
8-
8+
* Add this action to your workflow:
99
```yaml
10-
uses: leigholiver/commit-with-deploy-key@v1.0.2
10+
uses: leigholiver/commit-with-deploy-key@v1.0.3
1111
with:
1212
source: build_output
1313
destination_folder: dist
@@ -16,30 +16,19 @@ with:
1616
```
1717
1818
## Inputs
19-
### `source`
20-
**Required** The file/directory to commit
21-
22-
### `deploy_key`
23-
**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
24-
25-
### `destination_repo`
26-
**Required** Git repository to push changes to
27-
28-
### `destination_folder`
29-
Directory in the destination repo to push changes to (default `.`)
30-
31-
### `destination_branch`
32-
Branch in destination repo to push changes to (default `main`)
33-
34-
### `delete_destination`
35-
Delete destination directory contents before copy? (default `false`)
36-
37-
### `git_username`/`git_email`
38-
Github user to use for the commit (default: `${{ github.actor }}`)
39-
40-
### `commit_message`
41-
Commit message (default `<action name> from <commit hash>`)
19+
| Name | Required | Default | Description |
20+
|--------------------- |--------- |----------------------------------- |---------------------------------------------------------|
21+
| `source` | `true` | | The file/directory to commit |
22+
| `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 |
23+
| `destination_repo` | `true` | | Git repository to push changes to |
24+
| `destination_folder` | `false` | `.` | Directory in the destination repo to push changes to |
25+
| `destination_branch` | `false` | `main` | Branch in destination repo to push changes to |
26+
| `delete_destination` | `false` | `false` | Delete destination directory contents before copy? |
27+
| `git_username` | `false` | `${{ github.actor }}` | Github user to use for the commit |
28+
| `git_email` | `false` | `${{ github.actor }}` | Github user to use for the commit |
29+
| `commit_message` | `false` | `<action name> from <commit hash>` | Commit message |
4230

4331
## Outputs
44-
### `commit_hash`
45-
SHA hash of the generated commit
32+
| Name | Description |
33+
|---------------|----------------------------------|
34+
| `commit_hash` | SHA hash of the generated commit |

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.0.2
1+
v1.0.3

entrypoint.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ elif [ -d $CALLING_DIR/$INPUT_SOURCE ]; then
4242
cp -a $CALLING_DIR/$INPUT_SOURCE/* .
4343
fi
4444

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

5050
# output the commit hash

0 commit comments

Comments
 (0)