Skip to content

Test for auto deployment #8

Test for auto deployment

Test for auto deployment #8

Workflow file for this run

name: Deploy on push
on:
push:
branches:
- master
# ignore if the files committed come only from this directory
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#example-excluding-paths
paths-ignore:
- '.github/**'
- 'docs/**'
defaults:
run:
shell: bash
# We use a PAT to connect to the GitOps repo
# https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
# because the default GITHUB_TOKEN has only access to the default Combostrap Organisation
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
jobs:
deploy-main-push:
runs-on: ubuntu-latest
steps:
- name: Check out the site repository
uses: actions/checkout@v3
- name: Get the last commit hash on main
run: |
set -Eeuo pipefail
echo "LAST_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: Check out the deploy repository
uses: actions/checkout@v3
with:
repository: gerardnico/kube-argocd
path: kube-argocd
token: ${{ secrets.ARGOCD_GITHUB_TOKEN }}
- name: Update commit in Kubernetes deployment manifest
env:
GITHUB_TOKEN: ${{ secrets.ARGOCD_GITHUB_TOKEN }}
run: |
echo "Patch Deployment with the last commit ($LAST_COMMIT)"
set -Eeuo pipefail
cd kube-argocd || (echo 'Fail Cd' && exit 1)
# Patch with the last commit the app deployment
sed -i "s/value: \".*\" # DOKU_DOCKER_GIT_SITE_COMMIT/value: \"$LAST_COMMIT\" # DOKU_DOCKER_GIT_SITE_COMMIT/" com-combostrap/com-combostrap-deployment.yml
# Do we have changes?
CHANGES_COUNT=$(git diff --name-only | wc -l)
if [ "$CHANGES_COUNT" == '0' ]; then
echo "No changes should not happen on push"
exit 1;
fi
echo "Deployment file has changed, pushing it"
git config --global user.email "[email protected]"
git config --global user.name "Nico"
git add com-combostrap/com-combostrap-deployment.yml
git commit -m "Updated commit in com-combostrap-deployment.yml (GitHub Workflow)"
git push origin main
echo "Done"