change branch to push to charts and stacked_charts #49
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 and Test Tender Document Generator | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
env: | |
IMAGE_TAG: 'v1.${{ github.run_number }}' | |
IMAGE_NAME: 'tender-docxtemplate-app' | |
CONTAINER_NAME: 'tender-docxtemplate-app' | |
CONTAINER_MAPPING_PORT: '8503:8503' | |
jobs: | |
build: | |
runs-on: ubuntu-dind | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Build Docker image | |
run: docker build --build-arg git_token=${{ secrets.GITHUB_TOKEN }} --build-arg CACHEBUST=$(date +%s) --build-arg BRANCH=main --build-arg OWNER=${{ github.repository_owner }} -t ${{ env.IMAGE_NAME }} . | |
- id: run_and_check_container_status | |
name: Run Tender app | |
uses: ./.github/actions/run_docker_container | |
with: | |
imageName: '${{ env.IMAGE_NAME }}' | |
containerName: '${{ env.CONTAINER_NAME }}' | |
containerMappingPort: '${{ env.CONTAINER_MAPPING_PORT }}' | |
- name: Downcase REPO | |
run: | | |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: '${{ github.repository_owner }}' | |
password: '${{ secrets.GITHUB_TOKEN }}' | |
- name: Push image to GitHub Container Registry | |
run: | | |
docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.REPO }}:${{ env.IMAGE_TAG }} | |
docker push ghcr.io/${{ env.REPO }}:${{ env.IMAGE_TAG }} | |
test: | |
needs: build | |
runs-on: robot-dind | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Downcase REPO | |
run: | | |
echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: '${{ github.repository_owner }}' | |
password: '${{ secrets.GITHUB_TOKEN }}' | |
- name: Pull image from GitHub Container Registry | |
run: | | |
docker pull ghcr.io/${{ env.REPO }}:${{ env.IMAGE_TAG }} | |
- id: run_and_check_container_status | |
name: Run Tender app | |
uses: ./.github/actions/run_docker_container | |
with: | |
imageName: 'ghcr.io/${{ env.REPO }}:${{ env.IMAGE_TAG }}' | |
containerName: '${{ env.CONTAINER_NAME }}' | |
containerMappingPort: '${{ env.CONTAINER_MAPPING_PORT }}' | |
- name: Run Robot Framework tests | |
run: | | |
echo "##[command]robot tests/" | |
robot tests/ | |
- name: Delete package from GHCR if test fails | |
if: failure() | |
run: | | |
echo "Robot test failed, deleting package from GHCR..." | |
REPO_NAME=$(echo ${{ env.REPO }} | cut -d'/' -f2) | |
echo "Repo name: $REPO_NAME" | |
VERSION_ID=$(curl -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.repository_owner }}/packages/container/$REPO_NAME/versions" | jq -r '.[] | select(.metadata.container.tags[] == "${{ env.IMAGE_TAG }}") | .id') | |
echo "Package version ID: $VERSION_ID" | |
curl -i -X DELETE -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -H "Accept: application/vnd.github.v3+json" "https://api.github.com/users/${{ github.repository_owner }}/packages/container/$REPO_NAME/versions/$VERSION_ID" | |
- name: 'Upload Artifact' | |
if: always() | |
uses: actions/upload-artifact@v4.6.0 | |
with: | |
name: robot-test-report | |
path: ./report.html | |
- name: Push latest image to GitHub Container Registry | |
run: | | |
docker tag ghcr.io/${{ env.REPO }}:${{ env.IMAGE_TAG }} ghcr.io/${{ env.REPO }}:latest | |
docker push ghcr.io/${{ env.REPO }}:latest | |
update: | |
needs: test | |
runs-on: ubuntu-dind | |
steps: | |
- name: Checkout charts | |
uses: actions/checkout@v4 | |
with: | |
repository: '${{ github.repository_owner }}/charts' | |
token: ${{ secrets.PUSH_TOKEN }} | |
path: charts | |
ref: main | |
- name: Checkout stacked_charts | |
uses: actions/checkout@v4 | |
with: | |
repository: '${{ github.repository_owner }}/stacked_charts' | |
token: ${{ secrets.PUSH_TOKEN }} | |
path: stacked_charts | |
ref: master | |
- name: Checkout SVTECH_CI_utilities | |
uses: actions/checkout@v4 | |
with: | |
repository: '${{ github.repository_owner }}/SVTECH_CI_utilities' | |
token: ${{ secrets.PUSH_TOKEN }} | |
path: SVTECH_CI_utilities | |
ref: dev-jenkins | |
- name: Helm tool installer | |
uses: Azure/setup-helm@v3 | |
- name: Setup Python | |
uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: "3.13" | |
- name: Import GPG key | |
uses: crazy-max/ghaction-import-gpg@v6.2.0 | |
with: | |
# GPG private key exported as an ASCII armored version or its base64 encoding | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
- name: Modify image version in charts | |
run: | | |
cd charts | |
sed -i '/^ repository: svtechnmaa\/tender_document_generator/{N;s/ tag: .*/ tag: '"${{ env.IMAGE_TAG }}"'/}' kubernetes/docxtemplate/values.yaml | |
- name: Update image version in stacked_charts | |
run: | | |
pip install requests pyyaml | |
python3 ./SVTECH_CI_utilities/auto_testing/python_script/public_helmchart_release.py --BUILD_VARS_PATH="." --ID="." --GITHUB_TOKEN=${{ secrets.PUSH_TOKEN }} --OWNER=svtechnmaa --charts_string=docxtemplate --REPO=charts | |
cd stacked_charts | |
if [[ `git diff --name-only` ]]; then | |
git config user.name "${{ env.GIT_USER_NAME }}" | |
git config user.email "${{ env.GIT_USER_EMAIL }}" | |
git config commit.gpgSign true | |
git config user.signingkey ${{ secrets.GPG_KEY_ID }} | |
git add . | |
git commit --no-verify -m "no-ci: Update docxtemplate image version to ${{ env.IMAGE_TAG }}" | |
git push origin master | |
else | |
echo "No changes to commit" | |
fi | |
env: | |
GIT_USER_NAME: "svtechnmaa" | |
GIT_USER_EMAIL: "nmaa@svtech.com.vn" | |
- name: Update image version in charts | |
run: | | |
cd charts | |
helm repo index artifacthub | |
if [[ `git diff --name-only` ]]; then | |
git config user.name "${{ env.GIT_USER_NAME }}" | |
git config user.email "${{ env.GIT_USER_EMAIL }}" | |
git config commit.gpgSign true | |
git config user.signingkey ${{ secrets.GPG_KEY_ID }} | |
git add . | |
git commit --no-verify -m "no-ci: Update docxtemplate image version to ${{ env.IMAGE_TAG }}" | |
git push origin main | |
else | |
echo "No changes to commit" | |
fi | |
env: | |
GIT_USER_NAME: "svtechnmaa" | |
GIT_USER_EMAIL: "nmaa@svtech.com.vn" |