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: 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_PATH: build/libs | |
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 }} | |
artifact-name: ${{ steps.cfg.outputs.artifact-name }} | |
# artifact-with-tag: ludoapp | |
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} | |
ARTIFACT_NAME="${{ env.APP_NAME }}-$DATE-$COMMIT_HASH-${{ env.ENV }}.jar" | |
echo "artifact-name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT | |
echo "generated artifact-name: $ARTIFACT_NAME" | |
# <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-name }} | |
artifact-build-path: ${{ env.ARTIFACT_BUILD_PATH }} | |
# JOB4-1 Unit Test | |
unit-test: | |
needs: [cfg, build-and-upload-artifact, trigger-provision-test-infra] | |
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: [cfg, build-and-upload-artifact, trigger-provision-test-infra] | |
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: [cfg, build-and-upload-artifact, trigger-provision-test-infra] | |
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: | |
[cfg, build-and-upload-artifact, unit-test, integration-test, e2e-test] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: containerization | |
uses: ./.github/workflows/actions/containerization | |
with: | |
env: ${{ env.ENV }} | |
dockerhub-username: ${{ vars.DOCKERHUB_USERNAME }} | |
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }} | |
artifact-name: ${{ needs.cfg.outputs.artifact-name }} | |
artifact-build-path: ${{ env.ARTIFACT_BUILD_PATH }} | |
# - name: download artifact | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: "${{ needs.cfg.outputs.artifact-name }}" | |
# path: ${{ env.ARTIFACT_BUILD_PATH }} | |
# - name: log in to dockerhub | |
# uses: docker/login-action@v2 | |
# with: | |
# username: ${{ vars.DOCKERHUB_USERNAME }} | |
# password: ${{ secrets.DOCKERHUB_TOKEN }} | |
# - name: set docker image name with tag | |
# run: | | |
# ARTIFACT_WITH_TAG=$(echo ${{ needs.cfg.outputs.artifact-name }} | sed 's/-/:/' ) | |
# ARTIFACT_WITH_TAG=${ARTIFACT_WITH_TAG%.*} | |
# echo "CONTAINER_IMAGE_PATH=${{ vars.DOCKERHUB_USERNAME }}/$ARTIFACT_WITH_TAG" >> $GITHUB_ENV | |
# echo "docker image name:tag will be `$CONTAINER_IMAGE_PATH`" | |
# - name: push docker container image | |
# uses: docker/build-push-action@v4 | |
# with: | |
# context: . | |
# push: true | |
# tags: ${{ env.CONTAINER_IMAGE_PATH }} | |
trigger-destroy-test-infra: | |
needs: [cfg, 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: ${{ env.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" |