Update version #11
Workflow file for this run
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: CI/CD | |
on: | |
push: | |
branches: | |
- '*' # matches every branch that doesn't contain a '/' | |
- '*/*' # matches every branch containing a single '/' | |
- '**' # matches every branch | |
tags: | |
- v* | |
pull_request: | |
branches: | |
- '*' # matches every branch that doesn't contain a '/' | |
- '*/*' # matches every branch containing a single '/' | |
- '**' # matches every branch | |
env: | |
UI_IMAGE_NAME: trialmonitor-ui | |
API_IMAGE_NAME: trialmonitor-api | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js 14.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 14 | |
cache: 'yarn' | |
cache-dependency-path: 'packages/server/yarn.lock' | |
- name: Install dependencies | |
working-directory: ./packages/server | |
run: yarn install --frozen-lockfile | |
- name: Run tests | |
working-directory: ./packages/server | |
run: npm test | |
# Push image to GitHub Packages. | |
# See also https://docs.docker.com/docker-hub/builds/ | |
push: | |
runs-on: ubuntu-latest | |
# Only build and deploy docker images if on master branch and not a PR | |
needs: [test] | |
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && needs.test.result != 'failure' | |
permissions: | |
packages: write | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build ui image | |
run: docker build packages/client/ --file packages/client/Dockerfile --tag $UI_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
- name: Build api image | |
run: docker build packages/server/ --file packages/server/Dockerfile --tag $API_IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | |
- name: Log in to registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | |
- name: Push ui image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$UI_IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "master" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag $UI_IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION | |
- name: Push api image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$API_IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "master" ] && VERSION=latest | |
echo IMAGE_ID=$IMAGE_ID | |
echo VERSION=$VERSION | |
docker tag $API_IMAGE_NAME $IMAGE_ID:$VERSION | |
docker push $IMAGE_ID:$VERSION |