Skip to content

refs/remotes/main~phu-teso #1545

refs/remotes/main~phu-teso

refs/remotes/main~phu-teso #1545

Workflow file for this run

name: vtd trigger
on:
repository_dispatch:
types:
- vtd-trigger
- refs/remotes/**
env:
REF_NAME: ${{ github.event.client_payload.ref_name}}
TRIGGERING_ACTOR: ${{ github.event.client_payload.triggering_actor}}
jobs:
build-and-check:
name: ${{ matrix.name }}
timeout-minutes: 60
runs-on: ubuntu-latest
outputs:
env: ${{ steps.target-branch.outputs.value == 'main' && 'dev' || 'stg' }}
strategy:
matrix:
include: ${{ fromJson(vars.STRATEGY_MATRIX_SERVICES) }}
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
repository: ${{ secrets.VTD_REPOSITORY_SOURCE }}
token: ${{ secrets.GH_PAT }}
ref: ${{ env.REF_NAME }}
path: source
- name: Check target source
id: target-branch
shell: bash
env:
GH_TOKEN: ${{ secrets.GH_PAT }}
run: |
HASH_REF=$(git ls-remote --heads --quiet --exit-code https://${{ secrets.GH_PAT }}@github.com/${{ secrets.VTD_REPOSITORY_TARGET }}${{ matrix.service }}.git ${{ env.REF_NAME }} || echo '' )
if [ -z "${HASH_REF}" ]; then
echo "value=main" >> $GITHUB_OUTPUT
else
echo "value=${{ env.REF_NAME }}" >> $GITHUB_OUTPUT
fi
- name: Checkout target
uses: actions/checkout@v4
with:
repository: ${{ secrets.VTD_REPOSITORY_TARGET }}${{ matrix.service }}
token: ${{ secrets.GH_PAT }}
ref: ${{ steps.target-branch.outputs.value }}
path: target
- name: Clone properties file
uses: actions/checkout@v4
with:
repository: ${{ secrets.VTD_REPOSITORY_ENV }}
token: ${{ secrets.GH_PAT }}
path: env
- name: Connect to VPN
uses: Boostport/setup-cloudflare-warp@v1
with:
organization: tesoglobal
auth_client_id: ${{ secrets.CF_ACCESS_CLIENT_ID }}
auth_client_secret: ${{ secrets.CF_ACCESS_CLIENT_SECRET }}
- name: Switch profile
run: |
sed -i "s|spring.profiles.active=local|spring.profiles.active=ci|g" source/src/main/resources/application.properties
mv env/v4-java/application-ci.properties source/src/main/resources/application-ci.properties
- name: Switch branch
if: steps.target-branch.outputs.value == 'main'
working-directory: target
run: |
git branch --delete -D ${{ env.REF_NAME }} || echo 'done!!!'
git fetch --all --quiet
git switch -c ${{ env.REF_NAME }} || echo 'already!!!'
git reset --hard ${{ env.REF_NAME }}
git pull origin ${{ env.REF_NAME }} || echo 'done!!!'
- name: Setup java 21
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21"
- name: Remove the rest code
run: |
mkdir code_temp
mv -v source/${{ secrets.SERVICE_PACKAGE_PATH }}/* code_temp
mv code_temp/main source/${{ secrets.SERVICE_PACKAGE_PATH }}/
mv code_temp/auth source/${{ secrets.SERVICE_PACKAGE_PATH }}/
mv code_temp/zoo source/${{ secrets.SERVICE_PACKAGE_PATH }}/
mv code_temp/Application.java source/${{ secrets.SERVICE_PACKAGE_PATH }}/
mv code_temp/ConfigProperties.java source/${{ secrets.SERVICE_PACKAGE_PATH }}/
mv code_temp/${{ matrix.service }} source/${{ secrets.SERVICE_PACKAGE_PATH }}/
- name: cleanup dbchange
run: |
if [ -d "source/src/main/resources/dbchange" ]; then
mkdir dbchange_temp
mv -v source/src/main/resources/dbchange/* dbchange_temp
mv dbchange_temp/${{ matrix.service }} source/src/main/resources/dbchange/
fi
- name: Remove the rest overlays
run: |
mkdir overlay_temp
mv -v source/overlays/* overlay_temp
mv overlay_temp/${{ matrix.service }} source/overlays/
- name: Change micro.service.context-path
working-directory: source
run: perl -i -pe "s/^micro.service.context-path=\/api/'micro.service.context-path=${{ matrix.path }}'/e" src/main/resources/application.properties
- name: Build and package project
working-directory: source
run: mvn -f pom.xml clean install package -DskipTests -q
- name: Move code to the result
run: |
mkdir result
mv target/.git result/
rm -rf source/.git
shopt -s dotglob
mv -v source/* result/
sed -i "s|spring.profiles.active=ci|spring.profiles.active=local|g" result/src/main/resources/application.properties
- name: Check changes
working-directory: result
id: is-change-code
run: |
if [[ `git status --porcelain` ]]; then
echo "value=true" >> $GITHUB_OUTPUT
else
echo "value=false" >> $GITHUB_OUTPUT
fi
- name: Push result
# if: steps.is-change-code.outputs.value == 'true'
working-directory: result
run: |
git config user.name "GitHub Actions" --local
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" --local
git add -A
git diff-index --quiet HEAD || git commit -m ':white_check_mark: update code'
git push origin ${{ env.REF_NAME }} -f
- name: Trigger build ${{ matrix.service }}
# if: steps.is-change-code.outputs.value == 'true'
working-directory: result
run: |
TRIGGERING_ACTOR=${{ env.TRIGGERING_ACTOR }}
TRIGGERING_REF=${{ env.REF_NAME }}
TRIGGERING_SERVICE_NAME=${{ matrix.service }}
TRIGGERING_REPOSITORY=${{ secrets.VTD_REPOSITORY_TARGET }}${{ matrix.service }}
TRIGGERING_ENV=${{ steps.target-branch.outputs.value == 'main' && 'dev' || 'stg' }}
TRIGHERING_VERSION=$(git rev-parse HEAD)
TRIGHERING_HASH=$(git rev-parse HEAD)
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.LIBERTY_PPAP_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/VitaDairy/vtd-be-ppap/dispatches \
-d "{ \
\"event_type\": \"vtd-be-java-${{ matrix.service }}/refs/remotes/$TRIGGERING_REF~$TRIGGERING_ACTOR\", \
\"client_payload\": { \
\"triggering_actor\": \"$TRIGGERING_ACTOR\", \
\"triggering_ref\": \"$TRIGGERING_REF\", \
\"triggering_service_name\": \"$TRIGGERING_SERVICE_NAME\", \
\"triggering_repo\": \"$TRIGGERING_REPOSITORY\", \
\"triggering_env\": \"$TRIGGERING_ENV\", \
\"triggering_version\": \"$TRIGHERING_VERSION\", \
\"triggering_hash\": \"$TRIGHERING_HASH\" \
} \
}"