fix links to youtube and meeting notes for TAG OpRes #108
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Generate README on Tags Change (Forked PR) | |
| on: | |
| pull_request_target: | |
| types: [opened, synchronize, reopened] | |
| branches: | |
| - main | |
| paths: | |
| - tags.yaml | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| update-readme-fork: | |
| # This job runs only if the PR is coming from a fork. | |
| if: ${{ github.event.pull_request.head.repo.full_name != github.repository }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ github.event.pull_request.head.repo.full_name }} | |
| ref: ${{ github.event.pull_request.head.ref }} # Ensure branch checkout | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: 'stable' | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| - name: Create new PR, comment and close original (forked PR) | |
| env: | |
| # Use github.token which has write permissions in pull_request_target context | |
| # This should allow closing PRs from forks. If TAGS_YAML_UPDATE_GHA secret is set, | |
| # it will be used instead (must have 'repo' scope for full permissions) | |
| GITHUB_TOKEN: ${{ secrets.TAGS_YAML_UPDATE_GHA || github.token }} | |
| run: | | |
| set -e | |
| cp tags.yaml /tmp/tags.yaml | |
| BRANCH_NAME=readme-update-fork-${{ github.event.pull_request.number }} | |
| git remote set-url origin https://github.com/${{ github.repository }}.git | |
| git fetch origin main | |
| git checkout -B $BRANCH_NAME origin/main | |
| cp /tmp/tags.yaml tags.yaml | |
| cd generator | |
| go run readme_app.go | |
| cd .. | |
| git config --global user.name "github-actions" | |
| git config --global user.email "github-actions@github.com" | |
| git add . | |
| if ! git diff --staged --quiet; then | |
| git commit -sm "Update README based on tags.yaml changes" | |
| git push origin $BRANCH_NAME --force | |
| PR_TITLE="Update README based on tags.yaml changes from fork PR #${{ github.event.pull_request.number }}" | |
| PR_BODY="This PR updates the README file based on changes in tags.yaml from fork PR #${{ github.event.pull_request.number }}." | |
| API_URL=https://api.github.com/repos/${{ github.repository }}/pulls | |
| PR_DATA=$(jq -n --arg title "$PR_TITLE" --arg head "$BRANCH_NAME" --arg base "${{ github.event.pull_request.base.ref }}" --arg body "$PR_BODY" '{title: $title, head: $head, base: $base, body: $body}') | |
| RESPONSE=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d "$PR_DATA" $API_URL) | |
| echo "PR creation response: $RESPONSE" | |
| NEW_PR_NUMBER=$(echo "$RESPONSE" | jq -r '.number') | |
| if [ "$NEW_PR_NUMBER" = "null" ]; then | |
| echo "Error: PR not created. API response: $RESPONSE" | |
| exit 1 | |
| fi | |
| # Try to close the original PR first | |
| CLOSE_API_URL=https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | |
| CLOSE_RESPONSE=$(curl -s -w "\n%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d '{ "state": "closed" }' $CLOSE_API_URL) | |
| HTTP_CODE=$(echo "$CLOSE_RESPONSE" | tail -n1) | |
| if [ "$HTTP_CODE" = "200" ]; then | |
| echo "Successfully closed PR #${{ github.event.pull_request.number }}" | |
| ORIGINAL_COMMENT="This PR has been superseded by [PR #$NEW_PR_NUMBER](https://github.com/${{ github.repository }}/pull/$NEW_PR_NUMBER) and has been automatically closed." | |
| else | |
| echo "Warning: Could not automatically close PR #${{ github.event.pull_request.number }} (HTTP code: $HTTP_CODE)" | |
| echo "Response: $CLOSE_RESPONSE" | |
| ORIGINAL_COMMENT="This PR has been superseded by [PR #$NEW_PR_NUMBER](https://github.com/${{ github.repository }}/pull/$NEW_PR_NUMBER). Please close this PR manually." | |
| fi | |
| # Add comment to original PR | |
| ORIGINAL_COMMENT_API_URL=https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments | |
| ORIGINAL_COMMENT_DATA=$(jq -n --arg body "$ORIGINAL_COMMENT" '{body: $body}') | |
| curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d "$ORIGINAL_COMMENT_DATA" $ORIGINAL_COMMENT_API_URL | |
| NEW_PR_COMMENT="This PR replaces fork PR [#${{ github.event.pull_request.number }}](https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }})." | |
| NEW_PR_COMMENT_API_URL=https://api.github.com/repos/${{ github.repository }}/issues/$NEW_PR_NUMBER/comments | |
| NEW_PR_COMMENT_DATA=$(jq -n --arg body "$NEW_PR_COMMENT" '{body: $body}') | |
| curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/json" -d "$NEW_PR_COMMENT_DATA" $NEW_PR_COMMENT_API_URL | |
| else | |
| echo "No changes to commit" | |
| fi |