|
| 1 | +name: rebuild dist/ if needed |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + build: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - uses: actions/checkout@v3 |
| 11 | + with: |
| 12 | + ref: ${{github.head_ref}} |
| 13 | + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token |
| 14 | + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo |
| 15 | + |
| 16 | + |
| 17 | + with: |
| 18 | + cache: 'npm' |
| 19 | + node-version-file: '.nvmrc' |
| 20 | + |
| 21 | + - run: npm install |
| 22 | + - name: build dist/ |
| 23 | + run: npm run build |
| 24 | + - run: | |
| 25 | + STATUS=$(git diff --quiet && echo clean || echo modified) |
| 26 | + echo "status=$(echo $STATUS)" >> $GITHUB_OUTPUT |
| 27 | + id: gitStatus |
| 28 | + - run: | |
| 29 | + echo ${{ steps.gitStatus.outputs.status }} |
| 30 | + echo ${{ contains(steps.gitStatus.outputs.status, 'modified') }} |
| 31 | + - name: Commit dist/ files |
| 32 | + if: contains(steps.gitStatus.outputs.status, 'modified') |
| 33 | + run: | |
| 34 | + set -x |
| 35 | + git config --local user.email "[email protected]" |
| 36 | + git config --local user.name "GitHub Action" |
| 37 | + git commit -m "rebuild dist/" -a |
| 38 | + - id: auth |
| 39 | + if: contains(steps.gitStatus.outputs.status, 'modified') |
| 40 | + uses: jnwng/github-app-installation-token-action@v2 |
| 41 | + with: |
| 42 | + appId: ${{ secrets.COMMIT_BUILD_TO_PR_APP_ID }} |
| 43 | + installationId: ${{ secrets.COMMIT_BUILD_TO_PR_INSTALLATION_ID }} |
| 44 | + privateKey: ${{ secrets.COMMIT_BUILD_TO_PR_PRIVATE_KEY }} |
| 45 | + - name: Push changes |
| 46 | + if: contains(steps.gitStatus.outputs.status, 'modified') |
| 47 | + uses: ad-m/github-push-action@master |
| 48 | + with: |
| 49 | + github_token: ${{ steps.auth.outputs.token }} |
| 50 | + branch: ${{github.head_ref}} |
0 commit comments