Test and deploy to production #101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and deploy to production | |
on: | |
release: | |
types: [published] | |
workflow_run: | |
workflows: ["Test and deploy to staging"] | |
branches: [master] | |
types: [completed] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
cache: 'npm' | |
- uses: docker/setup-buildx-action@v2 | |
- name: Build image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Containerfile | |
build-args: | | |
E2E=true | |
push: false | |
load: true | |
tags: toppi:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Start the application | |
run: docker-compose -f compose.ci.yml up -d | |
# Copy dependencies from the container | |
- name: Copy dependencies from the container | |
run: docker cp toppi:/opt/app-root/src/node_modules ./node_modules | |
# https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/ | |
- name: Get installed Playwright version | |
id: playwright-version | |
run: echo "PLAYWRIGHT_VERSION=$(node -e "console.log(require('./package-lock.json').dependencies['@playwright/test'].version)")" >> $GITHUB_ENV | |
- name: Cache playwright binaries | |
uses: actions/cache@v3 | |
id: playwright-cache | |
with: | |
path: | | |
~/.cache/ms-playwright | |
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }} | |
- run: npx playwright install --with-deps | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
- run: npx playwright install-deps | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
- name: Run your tests | |
env: | |
CI: true | |
run: npx playwright test | |
- name: Upload test results | |
if: failure() | |
uses: actions/upload-artifact@v3 | |
with: | |
name: playwright-report | |
path: playwright-report | |
build-and-push: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build image | |
id: build-image | |
uses: redhat-actions/buildah-build@v2 | |
with: | |
image: toppi | |
tags: production ${{ github.sha }} | |
containerfiles: | | |
./Containerfile | |
- name: Push to quay.io | |
uses: redhat-actions/push-to-registry@v2 | |
with: | |
image: ${{ steps.build-image.outputs.image }} | |
tags: ${{ steps.build-image.outputs.tags }} | |
registry: quay.io/toska | |
username: toska+github | |
password: ${{ secrets.QUAY_IO_TOKEN }} | |
sentry-release: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Pull image and create a container | |
run: docker create --name toppi quay.io/toska/toppi:production | |
- name: Copy assets from the container | |
run: docker cp toppi:/opt/app-root/src/dist ./dist | |
- name: Create Sentry release | |
uses: getsentry/action-release@v1 | |
env: | |
SENTRY_URL: https://toska.cs.helsinki.fi/ | |
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_TOKEN }} | |
SENTRY_ORG: toska | |
SENTRY_PROJECT: toppi | |
with: | |
environment: production | |
set_commits: 'skip' | |
sourcemaps: ./dist/assets | |
url_prefix: '~/assets' |