diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 3c966be..ead95a2 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -15,21 +15,67 @@ on: jobs: check-dist: runs-on: ubuntu-latest - + permissions: + contents: write + pull-requests: write steps: - uses: actions/checkout@v4 + - name: Cache Dependencies ⌛️ + uses: actions/cache@v4 + id: cache-node-modules + with: + path: 'node_modules' + key: ${{ runner.os }}-node_modules-${{ hashFiles('package*.json') }}-${{ hashFiles('.github/workflows/node.yml') }} - name: Setup Node uses: actions/setup-node@v4 with: node-version-file: '.nvmrc' + cache: npm - name: Install dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' run: npm ci - name: Rebuild the index.js file run: npm run build + - uses: peter-evans/find-comment@v3 + if: ${{ github.event_name == 'pull_request' }} + id: find-comment + with: + issue-number: ${{ github.event.number }} + comment-author: 'github-actions[bot]' + body-includes: '❌ Detected mismatch in the `dist` directory.' + - name: Delete old comment + uses: actions/github-script@v7 + if: ${{ github.event_name == 'pull_request' && steps.find-comment.outputs.comment-id != '' }} + with: + result-encoding: string + retries: 3 + script: | + github.rest.issues.deleteComment({ + comment_id: ${{ steps.find-comment.outputs.comment-id }}, + owner: context.repo.owner, + repo: context.repo.repo, + }) - name: Compare the expected and actual dist/ directories + id: diff run: | if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then - echo "Detected uncommitted changes after build. See status below:" + echo "❌ Detected uncommitted changes after build" + echo "💡 To fix it, you need to run 'npm run build' and commit and push the dist folder changes" + echo "👇 See status below" git diff exit 1 fi + - uses: actions/upload-artifact@v4 + if: ${{ failure() && steps.diff.conclusion == 'failure' }} + id: artifact-dist + with: + name: dist + path: dist/ + - uses: peter-evans/create-or-update-comment@v4 + if: ${{ failure() && steps.diff.conclusion == 'failure' && github.event_name == 'pull_request' }} + with: + issue-number: ${{ github.event.number }} + body: | + ❌ Detected mismatch in the `dist` directory. + + 💡 Tip: to fix this issue you need to run `npm run build`, commit and push the `dist` folder changes. diff --git a/dist/index.js b/dist/index.js index b304edb..c4a3e20 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24722,7 +24722,7 @@ class Action { const name = inputs.name || "World"; this.logger.info(`Hello ${name}`); await this.sleep(3000); - this.logger.info("Change: 5"); + this.logger.info("Change: 8"); this.logger.info("Finished github-action-nodejs-template"); } sleep(milliseconds) { diff --git a/src/action.ts b/src/action.ts index a1eaf10..b400d76 100644 --- a/src/action.ts +++ b/src/action.ts @@ -13,7 +13,7 @@ export class Action { const name = inputs.name || "World"; this.logger.info(`Hello ${name}`); await this.sleep(3000); - this.logger.info("Change: 5"); + this.logger.info("Change: 8"); this.logger.info("Finished github-action-nodejs-template"); }