| name: Header Sync | |
| on: | |
| workflow_dispatch: null | |
| schedule: | |
| - cron: "0 0 * * *" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| name: Update headers from nodejs/node | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - run: npm install | |
| - shell: bash | |
| id: check-changes | |
| name: Check Changes | |
| run: | | |
| COMMIT_MESSAGE=$(npm run --silent update-headers) | |
| VERSION=${COMMIT_MESSAGE##* } | |
| echo $COMMIT_MESSAGE | |
| npm run --silent write-symbols | |
| npm run --silent write-win32-def | |
| CHANGED_FILES=$(git status -s) | |
| BRANCH_NAME="update-headers/${VERSION}" | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "No changes exist. Nothing to do." | |
| else | |
| echo "Changes exist. Checking if branch exists: $BRANCH_NAME" | |
| if git ls-remote --exit-code --heads $GITHUB_SERVER_URL/$GITHUB_REPOSITORY $BRANCH_NAME >/dev/null; then | |
| echo "Branch exists. Nothing to do." | |
| else | |
| echo "Branch does not exists." | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_OUTPUT | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| - name: Create Pull Request | |
| id: cpr | |
| uses: peter-evans/create-pull-request@6d6857d36972b65feb161a90e484f2984215f83e # v6.0.5 | |
| if: ${{ steps.check-changes.outputs.BRANCH_NAME }} | |
| with: | |
| branch: ${{ steps.check-changes.outputs.BRANCH_NAME }} | |
| commit-message: ${{ steps.check-changes.outputs.COMMIT_MESSAGE }} | |
| title: ${{ steps.check-changes.outputs.COMMIT_MESSAGE }} | |
| author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
| body: Automated sync of headers with Node.js ${{ steps.check-changes.outputs.VERSION }} | |
| labels: headers | |
| delete-branch: true | |
| - name: Close existing PRs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| if: ${{ steps.cpr.outputs.pull-request-number }} | |
| run: | | |
| gh pr list --json number,author,title,labels --jq '[ .[] | select(.author.login == "app/github-actions" and .number != ${{ steps.cpr.outputs.pull-request-number }} and (.labels[]| select(.name =="headers" )))]' | jq -c '.[]' | | |
| while IFS=$"\n" read -r c; do | |
| pr_number=$(echo "$c" | jq -r '.number') | |
| gh pr close $pr_number --delete-branch --comment "Closing in favor of [#${{ steps.cpr.outputs.pull-request-number }}](${{ steps.cpr.outputs.pull-request-url }})." | |
| done |