|
| 1 | +name: Update Observe Frontend |
| 2 | + |
| 3 | +# When a release is published, find open gohome PRs that share |
| 4 | +# the same ticket ID (WH-xxx / WEKAPP-xxx) and update their |
| 5 | +# @weka/weka-ui-components dependency to the new version. |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + packages: read |
| 10 | + |
| 11 | +on: |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + |
| 15 | +jobs: |
| 16 | + find-prs: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + outputs: |
| 19 | + prs: ${{ steps.find.outputs.prs || '[]' }} |
| 20 | + version: ${{ steps.version.outputs.version }} |
| 21 | + steps: |
| 22 | + - name: Extract version from tag |
| 23 | + id: version |
| 24 | + env: |
| 25 | + TAG_NAME: ${{ github.event.release.tag_name }} |
| 26 | + run: echo "version=${TAG_NAME#v}" >> $GITHUB_OUTPUT |
| 27 | + |
| 28 | + - name: Checkout to read commit message |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 3 |
| 32 | + |
| 33 | + - name: Extract ticket from tagged commit |
| 34 | + id: tickets |
| 35 | + env: |
| 36 | + TAG: ${{ github.event.release.tag_name }} |
| 37 | + run: | |
| 38 | + TICKETS=$(git log -2 --format='%B' "$TAG" | grep -oE '(WH|WEKAPP)-[0-9]+' | sort -u | tr '\n' ',' || true) |
| 39 | + echo "tickets=${TICKETS%,}" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + - name: Find gohome PRs matching release tickets |
| 42 | + id: find |
| 43 | + if: steps.tickets.outputs.tickets != '' |
| 44 | + uses: actions/github-script@v8 |
| 45 | + env: |
| 46 | + TICKETS: ${{ steps.tickets.outputs.tickets }} |
| 47 | + with: |
| 48 | + github-token: ${{ secrets.PARENT_REPOS_TOKEN }} |
| 49 | + script: | |
| 50 | + function prMatchesTicket(pr, tickets) { |
| 51 | + const searchText = `${pr.title}\n${pr.body || ''}\n${pr.head.ref}`.toUpperCase(); |
| 52 | + return tickets.find(t => searchText.includes(t.toUpperCase())); |
| 53 | + } |
| 54 | +
|
| 55 | + const tickets = process.env.TICKETS.split(','); |
| 56 | +
|
| 57 | + const pulls = await github.paginate(github.rest.pulls.list, { |
| 58 | + owner: 'weka', |
| 59 | + repo: 'gohome', |
| 60 | + state: 'open', |
| 61 | + per_page: 100, |
| 62 | + }); |
| 63 | +
|
| 64 | + const matched = pulls |
| 65 | + .map(pr => ({ pr, ticket: prMatchesTicket(pr, tickets) })) |
| 66 | + .filter(({ ticket }) => ticket) |
| 67 | + .map(({ pr, ticket }) => ({ |
| 68 | + number: pr.number, |
| 69 | + branch: pr.head.ref, |
| 70 | + ticket, |
| 71 | + })); |
| 72 | +
|
| 73 | + core.setOutput('prs', JSON.stringify(matched)); |
| 74 | +
|
| 75 | + update-pr: |
| 76 | + needs: find-prs |
| 77 | + if: needs.find-prs.outputs.prs != '[]' |
| 78 | + runs-on: ubuntu-latest |
| 79 | + strategy: |
| 80 | + fail-fast: false |
| 81 | + matrix: |
| 82 | + pr: ${{ fromJson(needs.find-prs.outputs.prs) }} |
| 83 | + steps: |
| 84 | + - name: Checkout gohome PR branch |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + repository: weka/gohome |
| 88 | + token: ${{ secrets.PARENT_REPOS_TOKEN }} |
| 89 | + ref: ${{ matrix.pr.branch }} |
| 90 | + |
| 91 | + - name: Setup Node.js |
| 92 | + uses: actions/setup-node@v4 |
| 93 | + with: |
| 94 | + node-version: '20' |
| 95 | + registry-url: 'https://npm.pkg.github.com' |
| 96 | + scope: '@weka' |
| 97 | + |
| 98 | + - name: Setup Yarn |
| 99 | + run: corepack enable && corepack prepare yarn@4.9.2 --activate |
| 100 | + |
| 101 | + - name: Update weka-ui-components |
| 102 | + working-directory: observe/frontend |
| 103 | + env: |
| 104 | + VERSION: ${{ needs.find-prs.outputs.version }} |
| 105 | + WEKA_COMPONENTS_NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + run: yarn add "@weka/weka-ui-components@^$VERSION" |
| 107 | + |
| 108 | + - name: Commit and push |
| 109 | + env: |
| 110 | + VERSION: ${{ needs.find-prs.outputs.version }} |
| 111 | + TICKET: ${{ matrix.pr.ticket }} |
| 112 | + run: | |
| 113 | + git config user.name "github-actions[bot]" |
| 114 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 115 | +
|
| 116 | + if git diff --quiet; then |
| 117 | + exit 0 |
| 118 | + fi |
| 119 | +
|
| 120 | + git add observe/frontend/package.json observe/frontend/yarn.lock |
| 121 | + git commit -m "chore: update @weka/weka-ui-components to $VERSION ($TICKET)" |
| 122 | + git push |
0 commit comments