Skip to content

Commit

Permalink
Add new release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
markspolakovs committed Sep 1, 2024
1 parent fce7510 commit 41e7312
Show file tree
Hide file tree
Showing 12 changed files with 247 additions and 99 deletions.
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
208 changes: 148 additions & 60 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 @@ -23,83 +22,154 @@ jobs:
DATABASE_URL: postgres://root:postgres@localhost:5432/badger_test
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: Use Node.js 18.x
# uses: actions/setup-node@v4
# with:
# node-version: 18.x
# cache: "yarn"
# 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
# - name: Set ref in docker-compose
# 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
# - name: Start services
# 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
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
# - uses: ./.github/steps/setup-playwright
# with:
# working-directory: ./server

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

- name: Install Playwright OS dependencies
run: npx playwright install-deps
if: steps.playwright-cache.outputs.cache-hit == 'true'
# - name: Retart services
# run: |
# docker compose -f docker-compose.yml -f docker-compose-rc-test.yml restart server jobrunner

- name: Migrate database
run: yarn prisma:migrateProd
# - name: Run Playwright tests
# run: yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }}
# working-directory: ./server
# env:
# PLAYWRIGHT_HTML_REPORT: ${{ github.workspace }}/server/playwright-report

- name: Run Playwright tests
run: yarn ${{ runner.debug && 'test:e2e:debug' || 'test:e2e' }}
working-directory: ./server
env:
PLAYWRIGHT_HTML_REPORT: ${{ github.workspace }}/server/playwright-report
# - uses: actions/upload-artifact@v3
# if: failure()
# with:
# name: playwright-report-server
# 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

- uses: actions/upload-artifact@v3
if: failure()
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:
name: playwright-report-server
path: ./server/playwright-report/
retention-days: 30
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 }}",
});
Loading

0 comments on commit 41e7312

Please sign in to comment.