-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (88 loc) · 3.55 KB
/
ci-create-release-pr.yaml
File metadata and controls
100 lines (88 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
###############################################################################
# GitOps Release PR Creator (Reusable Workflow) — Demo
#
# Called by ci-pr-trigger.yaml. Compares new image tags against current
# .env file and creates/updates a PR if versions differ.
###############################################################################
name: "CI: Create release PR"
on:
workflow_call:
inputs:
baseBranch:
description: "Target branch for the PR"
required: true
type: string
backendTag:
description: "New backend image tag"
required: false
type: string
frontendTag:
description: "New frontend image tag"
required: false
type: string
envPath:
description: "Path to .env file with image tags"
required: true
type: string
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.baseBranch }}
- name: Read current image tags
id: current
run: |
source ${{ inputs.envPath }}
echo "currentBackendTag=${BACKEND_TAG}" >> $GITHUB_OUTPUT
echo "currentFrontendTag=${FRONTEND_TAG}" >> $GITHUB_OUTPUT
echo "Current backend: ${BACKEND_TAG}"
echo "Current frontend: ${FRONTEND_TAG}"
- name: Update image tags if changed
id: update
env:
BACKEND_TAG: ${{ inputs.backendTag }}
FRONTEND_TAG: ${{ inputs.frontendTag }}
CURRENT_BACKEND_TAG: ${{ steps.current.outputs.currentBackendTag }}
CURRENT_FRONTEND_TAG: ${{ steps.current.outputs.currentFrontendTag }}
ENV_PATH: ${{ inputs.envPath }}
run: |
changed=false
if [[ -n "${BACKEND_TAG}" && "${BACKEND_TAG}" != "${CURRENT_BACKEND_TAG}" ]]; then
echo "Updating backend: ${CURRENT_BACKEND_TAG} -> ${BACKEND_TAG}"
sed -i "s/^BACKEND_TAG=.*/BACKEND_TAG=${BACKEND_TAG}/" "${ENV_PATH}"
changed=true
fi
if [[ -n "${FRONTEND_TAG}" && "${FRONTEND_TAG}" != "${CURRENT_FRONTEND_TAG}" ]]; then
echo "Updating frontend: ${CURRENT_FRONTEND_TAG} -> ${FRONTEND_TAG}"
sed -i "s/^FRONTEND_TAG=.*/FRONTEND_TAG=${FRONTEND_TAG}/" "${ENV_PATH}"
changed=true
fi
echo "changed=${changed}" >> $GITHUB_OUTPUT
- name: Create pull request
id: cpr
if: steps.update.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v6
with:
branch: release/auto-update
base: ${{ inputs.baseBranch }}
title: "release: update images (${{ inputs.backendTag }}/${{ inputs.frontendTag }})"
body: |
Automated image tag update.
| Service | Previous | New |
|----------|----------|-----|
| Backend | `${{ steps.current.outputs.currentBackendTag }}` | `${{ inputs.backendTag }}` |
| Frontend | `${{ steps.current.outputs.currentFrontendTag }}` | `${{ inputs.frontendTag }}` |
commit-message: "release: backend=${{ inputs.backendTag }} frontend=${{ inputs.frontendTag }}"
delete-branch: true
- name: Enable auto-merge
if: steps.cpr.outputs.pull-request-operation == 'created'
uses: nick-fields/retry@v3
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
timeout_minutes: 15
max_attempts: 30
retry_wait_seconds: 30
command: gh pr merge ${{ steps.cpr.outputs.pull-request-number }} --auto --squash