diff --git a/.github/workflows/build-site-metadata.yml b/.github/workflows/build-site-metadata.yml index 323bc7a..fa8c0f1 100644 --- a/.github/workflows/build-site-metadata.yml +++ b/.github/workflows/build-site-metadata.yml @@ -12,16 +12,33 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.repo.fork && github.sha || github.head_ref }} - name: Build Site Metadata run: npx --yes github:AdobeDocs/adp-devsite-utils buildSiteMetadata -v + - name: Check for changes + id: check_changes + run: | + if git diff --quiet HEAD -- src/pages/adp-site-metadata.json; then + echo "No changes to commit, skipping commit and push" + echo "changed=false" >> $GITHUB_OUTPUT + else + echo "changed=true" >> $GITHUB_OUTPUT + fi + + - name: Recommend building metadata locally + if: github.event.pull_request.head.repo.fork == true && steps.check_changes.outputs.changed == 'true' + run: | + echo "::error::This PR is from a fork. Please run 'npm run buildSiteMetadata' locally and commit the updated src/pages/adp-site-metadata.json file." + exit 1 + - name: Commit and push if changed + if: steps.check_changes.outputs.changed == 'true' && github.event.pull_request.head.repo.full_name == github.repository run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add src/pages/adp-site-metadata.json - git diff --cached --quiet || git commit -m "Generate site metadata" + git commit -m "Generate site metadata" git pull --rebase git push