Skip to content

Workflow file for this run

name: Build container image with previously built artifact and push it to the hub
# DYNAMIC VALUES
# ENV(prod, stag)
defaults:
run:
shell: bash
on:
push:
branches:
- main
- stag
workflow_dispatch:
env:
ENV: ${{ github.ref == 'refs/heads/main' && 'prod' || 'stag' }}
VERSION: 1.0.0
APP_NAME: ludo
ARTIFACT_BUILD_DIR: _build
INFRA_REPOSITORY: zxcev/ludo-infra
PROVISION_TEST_INFRA_EVENT: provision-test-infra
DESTROY_TEST_INFRA_EVENT: destroy-test-infra
PROVISION_TEST_ACTION_FILE: test-provision.yml
DESTROY_TEST_ACTION_FILE: test-destroy.yml
jobs:
# JOB1: CONF
cfg:
runs-on: ubuntu-latest
outputs:
artifact-with-tag: ${{ steps.cfg.outputs.artifact-with-tag }}
steps:
- name:
set environment variables
# if [[ ${{ github.ref }} == 'ref/heads/main' ]]; then
# echo "ENV=prod" >> $GITHUB_ENV
# fi
id: cfg
run: |
DATE=$(date +%y%m%d)
COMMIT_HASH=${GITHUB_SHA::7}
echo "artifact-with-tag=${{ env.APP_NAME }}:$DATE-$COMMIT_HASH-${{ env.ENV }}" >> $GITHUB_OUTPUT
# <app>-<env>-<date>-<hash>
# ludo:240101-510f224-dev
# JOB2: TRIGGER TEST INFRASTRUCTURE PROVISIONING
trigger-provision-test-infra:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: trigger provisioning infrastructure for tests
uses: ./.github/workflows/actions/trigger
with:
pat: ${{ secrets.PAT }}
repository: ${{ env.INFRA_REPOSITORY }}
event-type: ${{ env.PROVISION_TEST_INFRA_EVENT }}
action-file: ${{ env.PROVISION_TEST_ACTION_FILE }}
# JOB3: BUILD
build-and-upload-artifact:
needs: cfg
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup
uses: ./.github/workflows/actions/build_and_upload_artifact
with:
env: ${{ env.ENV }}
pat: ${{ secrets.PAT }}
artifact-name: ${{ needs.cfg.outputs.artifact-with-tag }}
artifact-build-dir: ${{ env.ARTIFACT_BUILD_DIR }}
# JOB4-1 Unit Test
unit-test:
needs: [build-and-upload-artifact, trigger-test-infra-provision]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup
uses: ./.github/workflows/actions/setup
with:
pat: ${{ secrets.PAT }}
- name: test with gradle
env:
TESTCONTAINERS_RYUK_DISABLED: true
run: ./gradlew test -Dspring.profiles.active=test
# JOB4-2 Integration Test
integration-test:
needs: [build-and-upload-artifact, trigger-test-infra-provision]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup
uses: ./.github/workflows/actions/setup
with:
pat: ${{ secrets.PAT }}
- name: do integration test
run: echo "fake integration test"
# # JOB4-3 E2E Test
e2e-test:
needs: [build-and-upload-artifact, trigger-test-infra-provision]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: setup
uses: ./.github/workflows/actions/setup
with:
pat: ${{ secrets.PAT }}
- name: do e2e test
run: echo "fake e2e test"
# # JOB5 BUILD CONTAINER IMAGE WITH JAR EXECUTABLE AND ENV
containerization:
needs: [unit-test, integration-test, e2e-test]
runs-on: ubuntu-latest
steps:
- name: download artifact
uses: actions/download-artifact@v3
with:
name: ${{ needs.cfg.outputs.artifact-with-tag }}
path: ${{ env.ARTIFACT_BUILD_DIR }}
- name: log in to dockerhub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: push docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: "${{ vars.DOCKERHUB_USERNAME }}/${{ needs.cfg.outputs.artifact-with-tag }}"
trigger-destroy-test-infra:
needs: [unit-test, integration-test, e2e-test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: generate token
id: infra
shell: bash
run: echo "token=$(openssl rand -hex 16)" >> $GITHUB_OUTPUT
- name: dispatch event to a specific Github repository
uses: peter-evans/repository-dispatch@v2
with:
# secrets.GITHUB_TOKEN doesn't have access permission to other repositories
# so use pat
token: ${{ secrets.PAT }}
repository: ${{ github.repository }}
event-type: ${{ DESTROY_TEST_INFRA_EVENT }}

Check failure on line 160 in .github/workflows/ci.yml

View workflow run for this annotation

GitHub Actions / Build container image with previously built artifact and push it to the hub

Invalid workflow file

The workflow is not valid. .github/workflows/ci.yml (Line: 160, Col: 23): Unrecognized named-value: 'DESTROY_TEST_INFRA_EVENT'. Located at position 1 within expression: DESTROY_TEST_INFRA_EVENT
client-payload: |
{
"trigger_repo": "${{ github.repository }}",
"trigger_sha": "${{ github.sha }}",
"verification_token": "${{ steps.infra.outputs.token }}"
}
# # notification:
# # needs: [trigger-test-infra-provision, conf, build-and-test]
# # runs-on: ubuntu-latest
# # if: always()
# # steps:
# # - name: check job status
# # env:
# # INFRA_STATUS: ${{ needs.trigger-test-infra-provision.result }}
# # CONF_STATUS: ${{ needs.cfg.result }}
# # BUILD_TEST_STATUS: ${{ needs.build-and-test.result }}
# # run: |
# # echo "Infra Provision status: $INFRA_STATUS"
# # echo "Build and Test status: $BUILD_TEST_STATUS"