Merge pull request 'Added automatically creating a pull request for ops-deployment with an update image number' (#2) from feature/create-deployment-merge-request into main
All checks were successful
Build & Publish to GHCR / build (push) Successful in 21s
All checks were successful
Build & Publish to GHCR / build (push) Successful in 21s
Reviewed-on: #2
This commit is contained in:
commit
dc0a1fb923
@ -4,9 +4,17 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
GHCR_ORG: gansejunge
|
||||
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:
|
||||
build:
|
||||
@ -23,7 +31,7 @@ jobs:
|
||||
run: |
|
||||
BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64)
|
||||
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')
|
||||
NEXT_TAG=$((LATEST_TAG + 1))
|
||||
echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT
|
||||
@ -33,3 +41,44 @@ jobs:
|
||||
run: |
|
||||
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 }}
|
||||
|
||||
- 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