Skip to content

feat: Install the components after merge to Observe (WEKAPP-605465) #1

feat: Install the components after merge to Observe (WEKAPP-605465)

feat: Install the components after merge to Observe (WEKAPP-605465) #1

name: Update Observe Frontend
# When a release is published, find open gohome PRs that share
# the same ticket ID (WH-xxx / WEKAPP-xxx) and update their
# @weka/weka-ui-components dependency to the new version.
on:
release:
types: [published]
pull_request: # TODO: remove after testing
workflow_dispatch:
inputs:
tag:
description: 'Tag to simulate (e.g. v4.1.1)'
required: true
ticket:
description: 'Ticket to match (e.g. WH-1111) — skips commit message extraction'
required: false
jobs:
find-prs:
runs-on: ubuntu-latest
outputs:
prs: ${{ steps.find.outputs.prs }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Extract version from tag
id: version
env:
TAG_NAME: ${{ inputs.tag || github.event.release.tag_name || 'v3.214.0' }} # TODO: remove fallback after testing
run: echo "version=${TAG_NAME#v}" >> $GITHUB_OUTPUT
- name: Checkout to read commit message
if: inputs.ticket == ''
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract ticket from tagged commit
id: tickets
env:
TAG: ${{ inputs.tag || github.event.release.tag_name }}
MANUAL_TICKET: ${{ inputs.ticket }}
run: |
if [ -n "$MANUAL_TICKET" ]; then
echo "tickets=$MANUAL_TICKET" >> $GITHUB_OUTPUT
elif [ -n "$TAG" ]; then
TICKETS=$(git log -2 --format='%B' "$TAG" | grep -oE '(WH|WEKAPP)-[0-9]+' | sort -u | tr '\n' ',')
echo "tickets=${TICKETS%,}" >> $GITHUB_OUTPUT
else
echo "tickets=WH-1111" >> $GITHUB_OUTPUT # TODO: remove fallback after testing
fi
- name: Find gohome PRs matching release tickets
id: find
if: steps.tickets.outputs.tickets != ''
uses: actions/github-script@v8
with:
github-token: ${{ secrets.PARENT_REPOS_TOKEN }}
script: |
function prMatchesTicket(pr, tickets) {
const searchText = `${pr.title}\n${pr.body || ''}\n${pr.head.ref}`
.replace(/…\n/g, '')
.toUpperCase();
return tickets.find(t => searchText.includes(t.toUpperCase()));
}
const tickets = '${{ steps.tickets.outputs.tickets }}'.split(',');
const pulls = await github.paginate(github.rest.pulls.list, {
owner: 'weka',
repo: 'gohome',
state: 'open',
per_page: 100,
});
const matched = pulls
.map(pr => ({ pr, ticket: prMatchesTicket(pr, tickets) }))
.filter(({ ticket }) => ticket)
.map(({ pr, ticket }) => ({
number: pr.number,
branch: pr.head.ref,
ticket,
}));
core.setOutput('prs', JSON.stringify(matched));
update-pr:
needs: find-prs
if: needs.find-prs.outputs.prs != '[]'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
pr: ${{ fromJson(needs.find-prs.outputs.prs) }}
steps:
- name: Checkout gohome PR branch
uses: actions/checkout@v4
with:
repository: weka/gohome
token: ${{ secrets.PARENT_REPOS_TOKEN }}
ref: ${{ matrix.pr.branch }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
scope: '@weka'
- name: Setup Yarn
run: corepack enable && corepack prepare yarn@4.9.2 --activate
- name: Update weka-ui-components
working-directory: observe/frontend
env:
VERSION: ${{ needs.find-prs.outputs.version }}
WEKA_COMPONENTS_NPM_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: yarn add "@weka/weka-ui-components@^$VERSION"
- name: Commit and push
env:
VERSION: ${{ needs.find-prs.outputs.version }}
TICKET: ${{ matrix.pr.ticket }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if git diff --quiet; then
exit 0
fi
git add observe/frontend/package.json observe/frontend/yarn.lock
git commit -m "chore: update @weka/weka-ui-components to $VERSION ($TICKET)"
git push