Skip to content

test workflow

test workflow #14

Workflow file for this run

name: 'Deploy'
on:
push:
branches: ['workshop/*']
jobs:
set-name:
name: 'Get name from branch name and set output'
outputs:
my_name: ${{ steps.set-name.outputs.my_name }}
runs-on: ubuntu-latest
steps:
- name: 'Set name'
id: set-name
run: echo "my_name=${BRANCH##*/}" >> "$GITHUB_OUTPUT"
env:
BRANCH: ${{ github.ref_name }}
run-tests:
name: 'Run frontend tests'
runs-on: ubuntu-latest
defaults:
run:
working-directory: 'frontend'
steps:
- name: Checkout repository
# Task A.1:
#
# Answer A.1:
uses: actions/checkout@v4
#
- name: Install dependencies
# Task A.1:
#
# Answer A.1:
run: yarn install
#
- name: Run tests
# Task A.1:
#
# Answer A.1:
run: yarn test
#
build:
name: 'Build Docker image and push to registry'
# Task A.2:
# needs: [set-name]
# Answer A.2:
needs: [set-name, run-tests]
#
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
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 Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push image to registry
uses: docker/build-push-action@v5
with:
push: 'true'
tags: 'ghcr.io/${{ github.repository }}/${{ needs.set-name.outputs.my_name }}:latest'
context: 'frontend'
deploy:
name: 'Deploy using Terraform'
runs-on: ubuntu-latest
needs: [build]
env:
TF_VAR_revision_suffix: ${{ github.sha }}
TF_VAR_my_name: ${{ needs.set-name.outputs.my_name }}
ARM_CLIENT_ID: ${{ vars.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ vars.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.ARM_TENANT_ID }}
ARM_USE_OIDC: 'true'
permissions:
contents: read
id-token: write
environment: prod
defaults:
run:
working-directory: 'terraform'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Init Terraform
run: terraform init
- name: Set Terraform workspace
run: terraform workspace new $MY_NAME || terraform workspace select $MY_NAME
- name: Run Terraform plan
run: terraform plan
- name: Run Terraform apply
# Task A.3
#
# Answer A.3
run: terraform apply -auto-approve
#