RED-16 - reworking frontend tests and user settings #158
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | |
name: Node.js CI/CD | |
on: | |
push: | |
branches: [ "main", "develop" ] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
prepare-tag: | |
if: github.ref == 'refs/heads/main' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Prepare release timestamp | |
id: step1 | |
run: | | |
echo "CI_TAG=$(date +'%0Y.%0m.%0d')-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
outputs: | |
ci_tag: ${{ steps.step1.outputs.CI_TAG }} | |
run-tests-frontend: | |
defaults: | |
run: | |
working-directory: web-app-vue | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16.x, 18.x, 20.x] | |
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
cache-dependency-path: web-app-vue/package-lock.json | |
- name: Run tests frontend | |
run: | | |
npm ci | |
npm run build --if-present | |
npm run test:web --if-present | |
run-tests-backend: | |
defaults: | |
run: | |
working-directory: service-node-koa | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [16.x, 18.x, 20.x] | |
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
cache-dependency-path: service-node-koa/package-lock.json | |
- name: Run tests | |
run: | | |
npm ci | |
npm run build --if-present | |
npm run test:service:coverage --if-present | |
publish-docker-image-frontend: | |
if: github.ref == 'refs/heads/main' | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: [ run-tests-frontend, prepare-tag ] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
env: | |
VITE_API_URL: ${{vars.VITE_API_URL}} | |
with: | |
push: true | |
context: "{{defaultContext}}:web-app-vue" | |
file: infrastructure/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
ghcr.io/sombriks/redline/redline-app:latest | |
ghcr.io/sombriks/redline/redline-app:${{needs.prepare-tag.outputs.ci_tag}} | |
publish-docker-image-backend: | |
if: github.ref == 'refs/heads/main' | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: [run-tests-backend, prepare-tag] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
context: "{{defaultContext}}:service-node-koa" | |
file: infrastructure/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
ghcr.io/sombriks/redline/redline-api:latest | |
ghcr.io/sombriks/redline/redline-api:${{needs.prepare-tag.outputs.ci_tag}} | |
update-iac-manifests: | |
if: github.ref == 'refs/heads/main' | |
permissions: write-all | |
runs-on: ubuntu-latest | |
needs: [prepare-tag, publish-docker-image-frontend, publish-docker-image-backend] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Update api image | |
uses: fjogeleit/yaml-update-action@main | |
with: | |
valueFile: service-node-koa/infrastructure/k8s/deployment.yml | |
propertyPath: spec.template.spec.containers[0].image | |
value: ghcr.io/sombriks/redline/redline-api:${{needs.prepare-tag.outputs.ci_tag}} | |
commitChange: false | |
- name: Update app image | |
uses: fjogeleit/yaml-update-action@main | |
with: | |
valueFile: web-app-vue/infrastructure/k8s/deployment.yml | |
propertyPath: spec.template.spec.containers[0].image | |
value: ghcr.io/sombriks/redline/redline-app:${{needs.prepare-tag.outputs.ci_tag}} | |
commitChange: false | |
- name: Update and tag modified manifests | |
run: | | |
git config user.name "Mr. Bob Tags" | |
git config user.email [email protected] | |
git status | |
git pull | |
git add . | |
git commit -m "IaC updated ${{needs.prepare-tag.outputs.ci_tag}}" | |
git push origin main | |
git tag ${{needs.prepare-tag.outputs.ci_tag}} | |
git push origin ${{needs.prepare-tag.outputs.ci_tag}} | |