Added page id #23
This file contains hidden or 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: 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 }} | |
# See doc: https://argo-cd.readthedocs.io/en/latest/user-guide/ci_automation/ | |
- 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 | |
APP_MANIFEST_PATH=apps/com-combostrap/com-combostrap-deployment.yml | |
# 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/" "$APP_MANIFEST_PATH" | |
# 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 "$APP_MANIFEST_PATH" | |
git commit -m "Updated commit in $APP_MANIFEST_PATH (GitHub Workflow)" | |
git push origin main | |
echo "Done" |