Added automatically creating a pull request for ops-deployment with an update image number
This commit is contained in:
parent
8d2020818d
commit
dc04f2bbec
@ -4,9 +4,17 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
|
GHCR_ORG: gansejunge
|
||||||
IMAGE_NAME: app-notifications-backend-api
|
IMAGE_NAME: app-notifications-backend-api
|
||||||
|
IMAGE_PATH: ghcr.io/gansejunge/app-notifications-backend-api
|
||||||
|
OPS_ORG: notifier
|
||||||
|
OPS_REPO: ops-deployment
|
||||||
|
OPS_BRANCH_BASE: main
|
||||||
|
OPS_PATH: backend-api/deployment.yaml
|
||||||
|
GITEA_URL: https://git.gansejunge.com
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@ -23,7 +31,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64)
|
BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64)
|
||||||
LATEST_TAG=$(curl -s -H "Authorization: Bearer $BASE64_TOKEN" \
|
LATEST_TAG=$(curl -s -H "Authorization: Bearer $BASE64_TOKEN" \
|
||||||
https://ghcr.io/v2/gansejunge/${{ env.IMAGE_NAME }}/tags/list \
|
https://ghcr.io/v2/${{ env.GHCR_ORG }}/${{ env.IMAGE_NAME }}/tags/list \
|
||||||
| jq -r '.tags | map(select(test("^[0-9]+$"))) | map(tonumber) | max // 0')
|
| jq -r '.tags | map(select(test("^[0-9]+$"))) | map(tonumber) | max // 0')
|
||||||
NEXT_TAG=$((LATEST_TAG + 1))
|
NEXT_TAG=$((LATEST_TAG + 1))
|
||||||
echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT
|
echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT
|
||||||
@ -33,3 +41,44 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker build -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} .
|
docker build -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} .
|
||||||
docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }}
|
docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }}
|
||||||
|
|
||||||
|
- name: Clone ops-deployment repo
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: notifier/ops-deployment
|
||||||
|
path: ./ops-deployment
|
||||||
|
token: ${{ secrets.BOT_TOKEN }}
|
||||||
|
|
||||||
|
- name: Update backend-api deployment
|
||||||
|
working-directory: ./ops-deployment
|
||||||
|
run: |
|
||||||
|
NEW_TAG=${{ steps.get_tag.outputs.next }}
|
||||||
|
NEW_IMAGE="${{ env.IMAGE_PATH }}:$NEW_TAG"
|
||||||
|
BRANCH_NAME="update-backend-api-$NEW_TAG"
|
||||||
|
git config user.name "automation-bot"
|
||||||
|
git config user.email "automation-bot@gansejunge.com"
|
||||||
|
git checkout -b $BRANCH_NAME
|
||||||
|
|
||||||
|
sed -i "s|ghcr.io/$GHCR_ORG/$IMAGE_NAME:[0-9]\+|$NEW_IMAGE|g" "$OPS_PATH"
|
||||||
|
|
||||||
|
COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
|
||||||
|
git add $OPS_PATH
|
||||||
|
git commit -m "Update backend-api image to version $NEW_TAG" -m "Linked build commit: $COMMIT_URL"
|
||||||
|
git push -u origin $BRANCH_NAME
|
||||||
|
|
||||||
|
- name: Create Pull Request in Gitea
|
||||||
|
working-directory: ./ops-deployment
|
||||||
|
run: |
|
||||||
|
NEW_TAG=${{ steps.get_tag.outputs.next }}
|
||||||
|
BRANCH_NAME="update-backend-api-$NEW_TAG"
|
||||||
|
COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}"
|
||||||
|
curl -X POST "$GITEA_URL/api/v1/repos/$OPS_ORG/$OPS_REPO/pulls" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: token ${{ secrets.$BOT_TOKEN }}" \
|
||||||
|
-d "{
|
||||||
|
\"head\": \"$BRANCH_NAME\",
|
||||||
|
\"base\": \"${{ vars.OPS_BRANCH_BASE }}\",
|
||||||
|
\"title\": \"Update backend-api image to version $NEW_TAG\",
|
||||||
|
\"body\": \"Automated update to backend-api image tag $NEW_TAG.\\n\\nLinked build commit: [$COMMIT_URL]($COMMIT_URL)\"
|
||||||
|
}"
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user