Make WordPress Core

Changeset 60063


Ignore:
Timestamp:
03/21/2025 04:33:17 PM (4 months ago)
Author:
desrosj
Message:

Build/Test Tools: Eliminate the need for custom tokens.

This reworks the workflow files introduced in [59983] to eliminate the need for a custom app token.

Follow up to [59983], [60052], [60059].

See #62221.

Location:
trunk/.github/workflows
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/check-built-files.yml

    r59984 r60063  
    1 # Checks for uncommitted changes to built files and pushes changes back.
    2 name: Check built files
     1# Checks for uncommitted changes to built files in pull requests.
     2name: Check Built Files (PRs)
    33
    44on:
     
    66  # runs for pull requests.
    77  #
    8   # Other workflows that run on push will detect changes to versioned files and fail.
    9   pull_request_target:
     8  # Other workflows that run for the push event will detect changes to versioned files and fail.
     9  pull_request:
    1010    branches:
    1111      - trunk
     
    3232  # The concurrency group contains the workflow name and the branch name for pull requests
    3333  # or the commit hash for any other events.
    34   group: ${{ github.workflow }}-${{ github.event_name == 'pull_request_target' && github.head_ref || github.sha }}
     34  group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
    3535  cancel-in-progress: true
    3636
     
    4040
    4141jobs:
    42   update-built-files:
    43     name: Update built files
    44     permissions:
    45       contents: write
    46     if: ${{ github.repository == 'WordPress/wordpress-develop' }}
    47     # This should always reference a version of the workflow committed through SVN and never a local reference.
    48     uses: WordPress/wordpress-develop/.github/workflows/reusable-check-built-files.yml@trunk
    49     secrets:
    50       GH_APP_ID: ${{ secrets.GH_PR_MANAGEMENT_APP_ID }}
    51       GH_APP_PRIVATE_KEY: ${{ secrets.GH_PR_MANAGEMENT_APP_PRIVATE_KEY }}
     42  check-for-built-file-changes:
     43    name: Check built files
     44    # This prevents an unnecessary second run after changes are committed back because Dependabot always rebases and force pushes.
     45    if: ${{ github.repository == 'wordpress/wordpress-develop' && ( github.actor != 'dependabot[bot]' || github.event.commits < 2 ) }}
     46    uses: ./.github/workflows/reusable-check-built-files.yml
  • trunk/.github/workflows/reusable-check-built-files.yml

    r60059 r60063  
    1 name: Lint GitHub Actions workflows
     1##
     2# A reusable workflow that checks for uncommitted changes to built files in pull requests.
     3##
     4name: Check Built Files (PRs)
     5
    26on:
    37  workflow_call:
    4     secrets:
    5       GH_APP_ID:
    6         description: 'A GitHub App ID.'
    7         required: true
    8       GH_APP_PRIVATE_KEY:
    9         description: 'A GitHub App private key.'
    10         required: true
    118
    129permissions: {}
     
    1512  # Checks a PR for uncommitted changes to built files.
    1613  #
    17   # This job uses a GitHub App instead of $GITHUB_TOKEN because Dependabot pull requests are only granted
    18   # read-only access.
     14  # When changes are detected, the patch is stored as an artifact for processing by the Commit Built File Changes
     15  # workflow.
    1916  #
    2017  # Performs the following steps:
    21   # - Generates a token for authenticating with the GitHub App.
    2218  # - Checks out the repository.
    2319  # - Sets up Node.js.
     
    3228  # - Checks for changes to versioned files.
    3329  # - Displays the result of git diff for debugging purposes.
    34   # - Configures the Git author.
    35   # - Stages changes.
    36   # - Commits changes.
    37   # - Pushes changes.
     30  # - Saves the diff to a patch file.
     31  # - Uploads the patch file as an artifact.
    3832  update-built-files:
    3933    name: Check and update built files
    4034    runs-on: ubuntu-24.04
    41     # This prevents an unnecessary second run after changes are committed back because Dependabot always rebases
    42     # updates and force pushes.
    43     if: ${{ github.actor != 'dependabot[bot]' || github.event.commits < 2 }}
    4435    timeout-minutes: 10
    45     permissions:
    46       contents: write
    4736    steps:
    48       - name: Generate Installation Token
    49         id: generate_token
    50         env:
    51           GH_APP_ID: ${{ secrets.GH_APP_ID }}
    52           GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
    53         run: |
    54           echo "$GH_APP_PRIVATE_KEY" > private-key.pem
    55 
    56           # Generate JWT
    57           JWT=$(python3 - <<EOF
    58           import jwt, time
    59           private_key = open("private-key.pem", "r").read()
    60           payload = {
    61               "iat": int(time.time()),
    62               "exp": int(time.time()) + 600,  # 10-minute expiration
    63               "iss": $GH_APP_ID
    64           }
    65           print(jwt.encode(payload, private_key, algorithm="RS256"))
    66           EOF
    67           )
    68 
    69           # Get Installation ID
    70           INSTALLATION_ID=$(curl -s -X GET -H "Authorization: Bearer $JWT" \
    71             -H "Accept: application/vnd.github.v3+json" \
    72             https://api.github.com/app/installations | jq -r '.[0].id')
    73 
    74           # Request Installation Access Token
    75           ACCESS_TOKEN=$(curl -s -X POST -H "Authorization: Bearer $JWT" \
    76             -H "Accept: application/vnd.github.v3+json" \
    77             "https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens" | jq -r '.token')
    78 
    79           echo "ACCESS_TOKEN=$ACCESS_TOKEN" >> "$GITHUB_ENV"
    80 
    81           rm -f private-key.pem
    82 
    8337      - name: Checkout repository
    8438        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
    8539        with:
    86           repository: ${{ github.event.pull_request.head.repo.full_name }}
    87           ref: ${{ github.event.pull_request.head.ref }}
    8840          show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
    89           token: ${{ env.ACCESS_TOKEN }}
    9041
    9142      - name: Set up Node.js
     
    14596        run: git diff
    14697
    147       - name: Configure git user name and email
     98      - name: Save diff to a file
    14899        if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
    149         run: |
    150           git config user.name "wordpress-develop-pr-bot[bot]"
    151           git config user.email ${{ secrets.GH_APP_ID }}+wordpress-develop-pr-bot[bot]@users.noreply.github.com
     100        run: git diff > ./changes.diff
    152101
    153       - name: Stage changes
     102      # Uploads the diff file as an artifact.
     103      - name: Upload diff file as artifact
     104        uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
    154105        if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
    155         run: git add .
    156 
    157       - name: Commit changes
    158         if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
    159         run: |
    160           git commit -m "Automation: Updating built files with changes. [dependabot skip]"
    161 
    162       - name: Push changes
    163         if: ${{ steps.built-file-check.outputs.uncommitted_changes == 'true' }}
    164         run: git push
     106        with:
     107          name: pr-built-file-changes
     108          path: changes.diff
Note: See TracChangeset for help on using the changeset viewer.