Skip to content

Commit abe1851

Browse files
Update commit.md
1 parent 6dd63f4 commit abe1851

File tree

1 file changed

+30
-6
lines changed
  • recipes/ci-cd/github-actions/workflows

1 file changed

+30
-6
lines changed

recipes/ci-cd/github-actions/workflows/commit.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,33 @@ When you might want to create and persist changes in CI:
1818
- Update table of contents.
1919

2020

21-
## Sample
21+
## Samples
2222

23-
Using the Publish to GitHub Action
23+
### No action
24+
25+
A simple way to commit any changes.
26+
27+
- `main.yml`
28+
```yaml
29+
steps:
30+
- run: # Modify files...
31+
32+
- name: Check for modified files
33+
id: git-check
34+
run: echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
35+
36+
- name: Push changes
37+
if: steps.git-check.outputs.modified == 'true'
38+
run: |
39+
git config --global user.name 'Automated Publisher'
40+
git config --global user.email 'actions@users.noreply.github.com'
41+
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
42+
git commit -am "Commit message..."
43+
git push
44+
```
45+
46+
47+
### Use the Publish to GitHub action
2448
2549
This uses an action maintained by GitHub - [actions/push-new-files-back-to-master](https://github.com/marketplace/actions/push-new-files-back-to-master).
2650
@@ -34,15 +58,15 @@ This uses an action maintained by GitHub - [actions/push-new-files-back-to-maste
3458
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3559
```
3660

37-
If you don't want to commit to master, you can specify a branch in `env` like so:
61+
If you don't want to commit to `master`, you can specify a branch in `env` like so:
3862

39-
```
63+
```yaml
4064
BRANCH_NAME: my-branch
4165
```
4266

4367
If you look at the code in the action, this is what is does (excluding validating variables and working with GitHub LFS).
4468

45-
I've refactored it.
69+
I've refactored it below.
4670

4771
- `entrypoint.sh`
4872
```sh
@@ -65,7 +89,7 @@ I've refactored it.
6589
git push publisher ${BRANCH_NAME}
6690
```
6791

68-
### Notes on the shell script
92+
#### Notes on the shell script
6993

7094
This action works on the root and doesn't let you target a build directory like `_site`. So this is not a good idea for GH Pages. Even if you switch from `master` to `gh-pages` and your `.md` files are gone, your unversioned files (cache and gems) won't be ignored properly and would be committed unnecessarily.
7195

0 commit comments

Comments
 (0)