Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BDGR-173] Add new automated release workflow #654

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/steps/setup-playwright/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Set Up Playwright
description: Sets up Playwright
inputs:
working-directory:
description: Where to run
required: false
runs:
using: composite
steps:
# Adapted from https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
- name: Get installed Playwright version
id: playwright-version
run: echo version=$(yarn info --json @playwright/test | jq -r '.children.Version') >> $GITHUB_OUTPUT
working-directory: ${{ inputs.working-directory }}
shell: bash

- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}

- name: Install Playwright Browsers
run: yarn playwright install --with-deps
working-directory: ${{ inputs.working-directory }}
if: steps.playwright-cache.outputs.cache-hit != 'true'
shell: bash

- name: Install Playwright OS dependencies
run: npx playwright install-deps
working-directory: ${{ inputs.working-directory }}
if: steps.playwright-cache.outputs.cache-hit == 'true'
shell: bash
39 changes: 33 additions & 6 deletions .github/workflows/build_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:
tag:
type: string
required: true
description: Docker tag to push
description: Version to build, also the docker tag
strip_rc:
type: boolean
description: Strip -rc suffix from version number

permissions:
contents: read
Expand All @@ -34,7 +37,17 @@ jobs:

- run: yarn install --immutable

- run: "yarn package"
- name: Set version
shell: pwsh
run: |
$pkg = Get-Content ./desktop/package.json | ConvertFrom-Json
$pkg.version = "${{inputs.tag }}" -replace "^v", ""
if ("${{ inputs.strip_rc }}" -eq "true") {
$pkg.version = $pkg.version -replace "-rc.*", ""
}
$pkg | ConvertTo-Json -Depth 32 | Set-Content ./desktop/package.json

- run: "yarn package --win --publish never"
working-directory: ./desktop
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -67,15 +80,23 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set version
run: |
set -x
version=$(echo '${{ inputs.tag }}' | sed 's/^v//')
if [[ '${{ inputs.strip_rc }}' == 'true' ]]; then
version=$(echo $version | sed 's/-rc.*//')
fi
cat package.json | jq '.version = "'$version'"' | tee package.json
working-directory: ./jobrunner
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/ystv/badger/server
flavor: latest=true
tags: |
type=semver,pattern={{version}},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_call' }}
type=raw,value=${{ inputs.tag }}
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand All @@ -101,15 +122,21 @@ jobs:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set version
run: |
version=$(echo '${{ inputs.tag }}' | sed 's/^v//')
if [[ '${{ inputs.strip_rc }}' == 'true' ]]; then
version=$(echo $version | sed 's/-rc.*//')
fi
cat package.json | jq '.version = "'$version'"' | tee package.json
- name: Docker metadata
id: jr_meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/ystv/badger/jobrunner
flavor: latest=true
tags: |
type=semver,pattern={{version}},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_call' }}
type=raw,value=${{ inputs.tag }}
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand Down
172 changes: 130 additions & 42 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ on:
tags:
- "*-rc*"

permissions:
contents: write
packages: write
permissions: write-all

jobs:
build:
uses: ./.github/workflows/build_shared.yml
with:
ref: ${{ github.event.before }}
tag: ${{ github.event.ref }}
ref: ${{ github.ref }}
tag: ${{ github.ref_name }}
strip_rc: true

test-e2e-server:
needs: [build]
Expand All @@ -31,36 +30,24 @@ jobs:
cache-dependency-path: "yarn.lock"

- name: Set ref in docker-compose
run: sed -i "s/__RC_REF__/${{ github.event.ref }}/g" docker-compose-rc-test.yml
run: sed -i "s/__RC_REF__/${{ github.ref_name }}/g" docker-compose-rc-test.yml

- name: Start services
run: docker compose up -d -f docker-compose.yml -f docker-compose-rc-test.yml
run: docker compose -f docker-compose.yml -f docker-compose-rc-test.yml up -d

# Adapted from https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
- name: Get installed Playwright version
id: playwright-version
run: echo version=$(yarn info --json @playwright/test | jq -r '.children.Version') >> $GITHUB_OUTPUT
working-directory: ./server
- run: yarn install --immutable --inline-builds

- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
- uses: ./.github/steps/setup-playwright
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}

- name: Install Playwright Browsers
run: yarn playwright install --with-deps
working-directory: ./server
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Install Playwright OS dependencies
run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'
working-directory: ./server

- name: Migrate database
run: yarn prisma:migrateProd
run: |
yarn prisma:migrateProd

- name: Retart services
run: |
docker compose -f docker-compose.yml -f docker-compose-rc-test.yml restart server jobrunner

- name: Run Playwright tests
run: yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }}
Expand All @@ -75,31 +62,114 @@ jobs:
path: ./server/playwright-report/
retention-days: 30

test-desktop:
runs-on: windows-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: "yarn.lock"
- name: Download Desktop build
uses: actions/download-artifact@v4
with:
name: badger-desktop-windows
- name: Install Badger
run: |
$version = "${{ github.ref_name }}" -replace "^v", "" -replace "-rc.*", ""
Start-Process -FilePath "Badger Desktop-$version.exe" -ArgumentList "/S","/D=${{ runner.temp }}\badger" -Wait
shell: pwsh
- run: yarn install --immutable --inline-builds
- name: Run tests
run: yarn test:e2e --project=standalone
working-directory: ./desktop
env:
TEST_APPLICATION_PATH: ${{ runner.temp }}\badger\Badger Desktop.exe

linear:
needs: [test-e2e-server, test-desktop]
runs-on: ubuntu-latest
outputs:
issue_id: ${{ steps.issue.outputs.issue_id }}
steps:
- name: Determine version number
run: echo "VERSION=$(echo '${{ github.ref_name }}' | sed 's/-rc.*//')" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- run: npm install @linear/sdk
- name: Create Linear release ticket
id: issue
uses: actions/github-script@v7
with:
script: |
const { LinearClient } = require('@linear/sdk');
const lin = new LinearClient({
accessToken: "${{ secrets.LINEAR_ACCESS_TOKEN }}"
});
const issueCreate = await lin.createIssue({
teamId: "${{ vars.LINEAR_TEAM_ID }}",
templateId: "${{ vars.LINEAR_RELEASE_ISSUE_TEMPLATE_ID }}",
stateId: "${{ vars.LINEAR_TODO_STATE_ID }}",
title: `Release ${{ github.ref_name }}`,
});
if (!issueCreate.success) {
throw new Error(`Failed to create issue`);
}
const issue = await issueCreate.issue;

await lin.createComment({
issueId: issue.id,
body: `Artifacts:
Server Docker image: \`ghcr.io/ystv/badger/server:${{ github.ref_name }}\`
Jobrunner Docker Image: \`ghcr.io/ystv/badger/jobrunner:${{ github.ref_name }}\`
Desktop Windows installer: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

Once testing is complete, please approve [this workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
`.replace(/^\s*/gm, ''),
});

core.summary.addHeading('Linear issue');
core.summary.addLink(issue.identifier, issue.url);
core.setOutput('issue_id', issue.id);

release:
needs: [test-e2e-server, build]
needs: [test-e2e-server, test-desktop, linear]
environment: release
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Determine version number
run: echo "VERSION=$(echo '${{ github.event.ref }}' | sed 's/^refs\/tags\///' | sed 's/-rc.*//')" >> $GITHUB_ENV
run: echo "VERSION=$(echo '${{ github.ref_name }}' | sed 's/-rc.*//')" >> $GITHUB_ENV
- name: Download Desktop build
uses: actions/download-artifact@v4
with:
pattern: badger-desktop-*
path: artifacts
- name: Pull Docker images
run: |
docker pull ghcr.io/ystv/badger/server:${{ github.event.ref }}
docker pull ghcr.io/ystv/badger/jobrunner:${{ github.event.ref }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Re-tag and push Docker images
run:
docker tag ghcr.io/ystv/badger/server:${{ github.event.ref }} ghcr.io/ystv/badger/server:$VERSION
docker tag ghcr.io/ystv/badger/jobrunner:${{ github.event.ref }} ghcr.io/ystv/badger/jobrunner:$VERSION
docker push ghcr.io/ystv/badger/server:$VERSION
docker push ghcr.io/ystv/badger/jobrunner:$VERSION
run: |
for img in server jobrunner; do
docker pull ghcr.io/ystv/badger/$img:${{ github.ref_name }}
docker tag ghcr.io/ystv/badger/$img:${{ github.ref_name }} ghcr.io/ystv/badger/$img:$VERSION
docker push ghcr.io/ystv/badger/$img:$VERSION
docker tag ghcr.io/ystv/badger/$img:${{ github.ref_name }} ghcr.io/ystv/badger/$img:latest
docker push ghcr.io/ystv/badger/$img:latest
done
shell: bash
- name: Create GitHub release
uses: actions/github-script@v7
id: release
with:
github-token: ${{ secrets.GH_RELEASE_PAT }}
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
Expand All @@ -109,21 +179,39 @@ jobs:
name: process.env.VERSION,
draft: true,
generate_release_notes: true,
make_latest: true
prerelease: false
});
core.setOutput('id', release.data.id)
core.setOutput('upload_url', release.data.upload_url)
core.setOutput('tag_name', release.data.tag_name)
- name: Upload artifacts
run: |
find artifacts -type f -exec gh release upload ${{ steps.release.outputs.tag_name }} {} \;
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }}
- name: Publish release
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.release.outputs.id }},
release_id: "${{ steps.release.outputs.id }}",
draft: false
})
- uses: actions/setup-node@v3
with:
node-version: "20.x"
- run: npm install @linear/sdk
- name: Close Linear issue
uses: actions/github-script@v7
with:
script: |
const { LinearClient } = require('@linear/sdk');
const lin = new LinearClient({
accessToken: "${{ secrets.LINEAR_ACCESS_TOKEN }}"
});
await lin.updateIssue({
issueId: "${{ needs.linear.outputs.issue_id }}",
stateId: "${{ vars.LINEAR_DONE_STATE_ID }}",
});
23 changes: 2 additions & 21 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,9 @@ jobs:
cp ../utility/prisma/schema.prisma .
working-directory: ./jobrunner

# Adapted from https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
- name: Get installed Playwright version
id: playwright-version
run: echo version=$(yarn info --json @playwright/test | jq -r '.children.Version') >> $GITHUB_OUTPUT
working-directory: ./server

- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
- uses: ./.github/steps/setup-playwright
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}

- name: Install Playwright Browsers
run: yarn playwright install --with-deps
working-directory: ./server
if: steps.playwright-cache.outputs.cache-hit != 'true'

- name: Install Playwright OS dependencies
run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'
working-directory: ./server

- name: Migrate database
run: yarn prisma:migrateProd
Expand Down
Loading
Loading