|
| 1 | +name: Yarn Upgrade Dependencies Requiring Intervention |
| 2 | +# This workflow upgrade npm dependencies that will require manual work. For example, `@aws-cdk/asset-awscli-v1` upgrade always require manually updating snapshots. |
| 3 | +# When adding deps in this workflow, we must also exclude them in the Yarn Upgrade workflow. This is so that the PR from that workflow can be kept clean (i.e. does not need manual update). |
| 4 | +# See this line on how to exclude deps: https://github.com/aws/aws-cdk/blob/ce7b30775f354c7de774f73c5f8dedd9ce7530d3/.github/workflows/yarn-upgrade.yml#L61 |
| 5 | +# If this proves to be too cumbersome, we can refactor both workflow to reference the deps list from a single place. |
| 6 | + |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + # Every wednesday at 13:37 UTC |
| 10 | + - cron: 37 13 * * 3 |
| 11 | + workflow_dispatch: {} |
| 12 | + |
| 13 | +# For multiple dependencies, do `DEPS_TO_UPGRADE:"p1 p2 p3"` |
| 14 | +env: |
| 15 | + DEPS_TO_UPGRADE: "@aws-cdk/asset-awscli-v1" |
| 16 | + |
| 17 | +jobs: |
| 18 | + upgrade: |
| 19 | + name: Yarn Upgrade |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check Out |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Node |
| 28 | + uses: actions/setup-node@v4 |
| 29 | + with: |
| 30 | + node-version: "*" |
| 31 | + env: |
| 32 | + NODE_OPTIONS: "--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}" |
| 33 | + |
| 34 | + - name: Locate Yarn cache |
| 35 | + id: yarn-cache |
| 36 | + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT |
| 37 | + |
| 38 | + - name: Restore Yarn cache |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: ${{ steps.yarn-cache.outputs.dir }} |
| 42 | + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} |
| 43 | + restore-keys: |- |
| 44 | + ${{ runner.os }}-yarn- |
| 45 | + - name: Yarn Install |
| 46 | + run: yarn install --frozen-lockfile |
| 47 | + - name: Install Tools |
| 48 | + run: |- |
| 49 | + npm -g install lerna npm-check-updates |
| 50 | + - name: Run "ncu -u" |
| 51 | + run: |- |
| 52 | + # Convert space-separated string to comma-separated string for the filter |
| 53 | + FILTER=$(echo "$DEPS_TO_UPGRADE" | tr ' ' ',') |
| 54 | + lerna exec --parallel ncu -- --upgrade --filter="$FILTER" --target=minor |
| 55 | +
|
| 56 | + - name: Run "yarn upgrade" |
| 57 | + run: | |
| 58 | + echo "Upgrading dependencies: $DEPS_TO_UPGRADE" |
| 59 | + yarn upgrade $DEPS_TO_UPGRADE --exact |
| 60 | +
|
| 61 | + # Next, create and upload the changes as a patch file. This will later be downloaded to create a pull request |
| 62 | + # Creating a pull request requires write permissions and it's best to keep write privileges isolated. |
| 63 | + - name: Create Patch |
| 64 | + run: |- |
| 65 | + git add . |
| 66 | + git diff --binary --patch --staged > ${{ runner.temp }}/upgrade.patch |
| 67 | +
|
| 68 | + - name: Upload Patch |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: upgrade.patch |
| 72 | + path: ${{ runner.temp }}/upgrade.patch |
| 73 | + |
| 74 | + pr: |
| 75 | + name: Create Pull Request |
| 76 | + needs: upgrade |
| 77 | + permissions: |
| 78 | + contents: write |
| 79 | + pull-requests: write |
| 80 | + runs-on: ubuntu-latest |
| 81 | + steps: |
| 82 | + - name: Check Out |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Download patch |
| 86 | + uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: upgrade.patch |
| 89 | + path: ${{ runner.temp }} |
| 90 | + |
| 91 | + - name: Apply patch |
| 92 | + run: '[ -s ${{ runner.temp }}/upgrade.patch ] && git apply --binary ${{ runner.temp |
| 93 | + }}/upgrade.patch || echo "Empty patch. Skipping."' |
| 94 | + |
| 95 | + - name: Make Pull Request |
| 96 | + uses: peter-evans/create-pull-request@v7 |
| 97 | + with: |
| 98 | + # Git commit details |
| 99 | + branch: automation/yarn-upgrade-dependencies-requiring-intervention |
| 100 | + author: aws-cdk-automation <aws-cdk-automation@users.noreply.github.com> |
| 101 | + commit-message: |- |
| 102 | + chore: npm-check-updates && yarn upgrade |
| 103 | + Ran npm-check-updates and yarn upgrade to keep the `yarn.lock` file up-to-date. |
| 104 | + # Pull Request details |
| 105 | + title: 'chore: yarn upgrade dependencies requiring intervention' |
| 106 | + body: |- |
| 107 | + Ran npm-check-updates and yarn upgrade for the following dependencies: |
| 108 | + ``` |
| 109 | + ${{ env.DEPS_TO_UPGRADE }} |
| 110 | + ``` |
| 111 | + Checkout this branch and run integration tests locally to update snapshots. |
| 112 | + ``` |
| 113 | + (cd packages/@aws-cdk-testing/framework-integ && yarn integ --update-on-failed) |
| 114 | + ``` |
| 115 | + See https://www.npmjs.com/package/@aws-cdk/integ-runner for more integ runner options. |
| 116 | + labels: contribution/core,dependencies |
| 117 | + team-reviewers: aws-cdk-team |
| 118 | + # Github prevents further Github actions to be run if the default Github token is used. |
| 119 | + # Instead use a privileged token here, so further GH actions can be triggered on this PR. |
| 120 | + token: ${{ secrets.PROJEN_GITHUB_TOKEN }} |
0 commit comments