|
4 | 4 | # access to the target repository from public forks. This should remain as a pull_request
|
5 | 5 | # trigger because checkout, build, format and checking for changes do not need elevated
|
6 | 6 | # permissions to the repository. The reduced permissions for public forks is adequate.
|
| 7 | + # Since this will commit readme/recompile changes back to the branch, special attention |
| 8 | + # should be paid to changes made to this workflow when reviewing the PR and granting |
| 9 | + # permission to first time contributors to run the workflow. |
7 | 10 | pull_request:
|
8 |
| - # Don't include any specific paths here so we always get a build that produces a status |
9 |
| - # check that our Branch Protection Rules can use. Having a status check also allows us |
10 |
| - # to require that branches be up to date before they are merged. |
11 |
| - |
| 11 | + # Don't include any specific paths here so we always get a build that produces a status |
| 12 | + # check that our Branch Protection Rules can use. Having a status check also allows us |
| 13 | + # to require that branches be up to date before they are merged. |
| 14 | + |
12 | 15 | jobs:
|
13 | 16 | build:
|
14 |
| - runs-on: ${{ matrix.operating-system }} |
15 |
| - strategy: |
16 |
| - fail-fast: false |
17 |
| - matrix: |
18 |
| - operating-system: [ubuntu-latest, windows-latest, macOS-latest] |
19 |
| - |
| 17 | + runs-on: ubuntu-latest |
| 18 | + |
20 | 19 | steps:
|
21 | 20 | - name: Checkout
|
22 | 21 | uses: actions/checkout@v3
|
| 22 | + with: |
| 23 | + ref: ${{ github.head_ref }} |
| 24 | + fetch-depth: 0 |
| 25 | + |
23 | 26 | - name: Setup Node.js 16
|
24 | 27 | uses: actions/setup-node@v3
|
25 | 28 | with:
|
26 | 29 | node-version: 16.x
|
27 |
| - - name: Build |
| 30 | + |
| 31 | + # If this step results in changes, they will be committed in the last step |
| 32 | + - name: Recompile and Format action |
28 | 33 | run: npm run build
|
29 |
| - - name: Format |
30 |
| - run: npm run format |
31 |
| - - name: Check for unstaged changes |
32 |
| - if: runner.os != 'windows' |
33 |
| - run: ./check-for-unstaged-changes.sh |
| 34 | + |
| 35 | + - name: Check for code changes to the action |
| 36 | + id: action-code |
| 37 | + uses: im-open/did-custom-action-code-change@v1.0.1 |
| 38 | + with: |
| 39 | + files-with-code: 'action.yml,package.json,package-lock.json' |
| 40 | + folders-with-code: 'src,dist' |
| 41 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Get the next version for the readme if there are code changes to the action |
| 44 | + if: steps.action-code.outputs.HAS_CHANGES == 'true' |
| 45 | + id: version |
| 46 | + uses: im-open/git-version-lite@v2.1.2 |
| 47 | + |
| 48 | + - name: Update readme with next version if there are code changes to the action |
| 49 | + if: steps.action-code.outputs.HAS_CHANGES == 'true' |
| 50 | + uses: im-open/update-action-version-in-file@v1.0.0 |
| 51 | + with: |
| 52 | + file-to-update: './README.md' |
| 53 | + action-name: ${{ github.repository }} |
| 54 | + updated-version: ${{ steps.version.outputs.NEXT_VERSION }} |
| 55 | + |
| 56 | + - name: Commit unstaged readme/recompile changes if there are code changes to the action |
| 57 | + if: steps.action-code.outputs.HAS_CHANGES == 'true' |
| 58 | + run: | |
| 59 | + if [[ "$(git status --porcelain)" != "" ]]; then |
| 60 | + echo "There are changes to commit" |
| 61 | + git config user.name github-actions |
| 62 | + git config user.email github-actions@github.com |
| 63 | + git add . |
| 64 | + git commit -m "Update readme with latest version and/or recompile the action." |
| 65 | + git push origin HEAD:${{ github.head_ref }} |
| 66 | + else |
| 67 | + echo "There were no changes to commit" |
| 68 | + fi |
0 commit comments