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 Aug 26, 2024
1 parent 8fb7a68 commit c8f077b
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,64 @@
name: Docker Image builds

on:
release:
types: [published]
workflow_dispatch:
workflow_call:
inputs:
ref:
type: string
required: true
description: "Branch, tag, or commit to build."
tag:
type: text
type: string
required: true
description: Tag to push
description: Docker tag to push

permissions:
contents: read
packages: write

jobs:
server:
build-desktop-windows:
runs-on: windows-latest
strategy:
matrix:
type: [public, ystv]

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: "yarn"
cache-dependency-path: "yarn.lock"

- run: yarn install --immutable

- run: "yarn package"
working-directory: ./desktop
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DESKTOP_SENTRY_DSN: ${{ secrets.DESKTOP_SENTRY_DSN }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
ENVIRONMENT: prod
IS_YSTV_BUILD: ${{ matrix.type == 'ystv' && 'true' || 'false' }}

- name: Clean up
run: Remove-Item -Recurse -Force ./desktop/dist/win-unpacked
shell: pwsh

- uses: actions/upload-artifact@v4
with:
path: ./desktop/dist
name: badger-desktop-windows${{ matrix.type == 'ystv' && '-ystv' || '' }}

build-docker-server:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
Expand All @@ -35,8 +74,8 @@ jobs:
images: ghcr.io/ystv/badger/server
flavor: latest=true
tags: |
type=semver,pattern={{version}}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_call' }}
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand All @@ -47,11 +86,13 @@ jobs:
cache-to: type=gha,mode=max
file: Dockerfile.server

jobrunner:
build-docker-jobrunner:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
Expand All @@ -67,8 +108,8 @@ jobs:
images: ghcr.io/ystv/badger/jobrunner
flavor: latest=true
tags: |
type=semver,pattern={{version}}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' }}
type=semver,pattern={{version}},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_call' }}
- name: Build and push
uses: docker/build-push-action@v6
with:
Expand Down
70 changes: 0 additions & 70 deletions .github/workflows/desktop-build.yml

This file was deleted.

129 changes: 129 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
on:
push:
tags:
- "*-rc*"

permissions:
contents: write
packages: write

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

test-e2e-server:
needs: [build]
runs-on: ubuntu-latest
env:
NODE_ENV: test
E2E_TEST: "true"
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: Set ref in docker-compose
run: sed -i "s/__RC_REF__/${{ github.event.ref }}/g" docker-compose-rc-test.yml

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

# 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
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'

- 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

- uses: actions/upload-artifact@v3
if: failure()
with:
name: playwright-report-server
path: ./server/playwright-report/
retention-days: 30

release:
needs: [test-e2e-server, build]
environment: release
runs-on: ubuntu-latest
steps:
- name: Determine version number
run: echo "VERSION=$(echo '${{ github.event.ref }}' | sed 's/^refs\/tags\///' | sed 's/-rc.*//')" >> $GITHUB_ENV
- name: Download Desktop build
uses: actions/download-artifact@v4
with:
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: 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
- name: Create GitHub release
uses: actions/github-script@v7
id: release
with:
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
target_commitish: context.sha,
tag_name: process.env.VERSION,
name: process.env.VERSION,
draft: true,
generate_release_notes: true,
make_latest: true
});
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 }} {} \;
- name: Publish release
uses: actions/github-script@v7
with:
script: |
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.release.outputs.id }},
draft: false
})
27 changes: 27 additions & 0 deletions docker-compose-rc-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"
services:
server:
image: ghcr.io/ystv/badger/server:__RC_REF__
platform: linux/amd64
ports:
- "3000:3000"
environment: &badger_env
DATABASE_URL: "postgres://root:postgres@postgres:5432/badger_test?sslmode=disable"
TUS_ENDPOINT: "http://tusd:1080/files"
PUBLIC_TUS_ENDPOINT: "http://localhost:1080/files"
S3_ENDPOINT: "http://minio:9000"
AWS_ACCESS_KEY_ID: "root"
AWS_SECRET_ACCESS_KEY: "rootroot"
AWS_REGION: "us-east-1"
STORAGE_BUCKET: "badger"
API_SHARED_SECRET: "password"
PUBLIC_URL: "http://localhost:3000"
JWT_SIGNING_KEY: "somesecret"
NODE_ENV: "test"
E2E_TEST: "true"

jobrunner:
image: ghcr.io/ystv/badger/jobrunner:__RC_REF__
platform: linux/amd64
command: ["--watch", "--healthPort", "28342"] # matching server/playwright.config.ts
environment: *badger_env
4 changes: 2 additions & 2 deletions server/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default defineConfig({
command: process.env.CI ? "node server/server.js" : "yarn dev",
cwd: process.env.CI ? ".next/standalone" : undefined,
url: "http://localhost:3000/api/healthz",
reuseExistingServer: !process.env.CI,
reuseExistingServer: true,
stdout: "pipe",
stderr: "pipe",
env: {
Expand All @@ -131,7 +131,7 @@ export default defineConfig({
cwd: "../jobrunner",
port: 28342,
env: serverEnv.parsed!,
reuseExistingServer: !process.env.CI,
reuseExistingServer: true,
stdout: "pipe",
stderr: "pipe",
},
Expand Down

0 comments on commit c8f077b

Please sign in to comment.