-
Notifications
You must be signed in to change notification settings - Fork 212
107 lines (92 loc) · 4.38 KB
/
create-deploy-resources.yml
File metadata and controls
107 lines (92 loc) · 4.38 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
101
102
103
104
105
106
107
name: Create deploy resources
env:
IMAGE_BASE_NAME: "quay.io/quarkus-super-heroes"
on:
workflow_call:
inputs:
commit_id:
description: The commit id of the original commit which triggered the workflow
required: true
type: string
branch:
description: The target branch of the commit id
required: true
type: string
workflow_dispatch:
jobs:
create-deploy-resources:
if: (github.repository == 'quarkusio/quarkus-super-heroes') && (contains(fromJSON('["workflow_dispatch", "schedule"]'), github.event_name) || ((github.event_name == 'worflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch') && (github.event.workflow_run.conclusion == 'success') && ((inputs.branch == 'main') || (inputs.branch == 'rhbq-2.7') || (inputs.branch == 'rhbq-2.13') || (inputs.branch == '2.13.Final') || (inputs.branch == '3.2.Final') || (inputs.branch == 'rhbq-3.2') || (inputs.branch == '3.8.Final') || (inputs.branch == 'rhbq-3.8') || (inputs.branch == '3.15.Final') || (inputs.branch == 'rhbq-3.15') || (inputs.branch == '3.20.Final') || (inputs.branch == 'rhbq-3.20')))))
runs-on: ubuntu-latest
permissions:
actions: read
contents: write
pull-requests: write
steps:
- name: Calculate Branch (NOT workflow_dispatch event)
if: github.event_name != 'workflow_dispatch'
run: |
echo "REF=${{ inputs.commit_id }}" >> $GITHUB_ENV
echo "BRANCH=${{ inputs.branch }}" >> $GITHUB_ENV
- name: Calculate Branch (workflow_dispatch event)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ github.sha }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout from ${{ env.REF }}
uses: actions/checkout@v6
with:
ref: ${{ env.REF }}
- name: Setup Java
uses: actions/setup-java@v5
with:
java-version: 21
distribution: temurin
cache: maven
- name: Create k8s resources
shell: bash
run: scripts/generate-k8s-resources.sh
- name: Create docker-compose resources
shell: bash
run: scripts/generate-docker-compose-resources.sh
- name: Create PR with generated resources
id: create-pr
env:
GH_TOKEN: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }}
run: |
SHORT_SHA=$(echo "${{ env.REF }}" | cut -c1-8)
PR_BRANCH="create-deploy-resources/sourceref-${SHORT_SHA}"
COMMIT_MSG="Generate deploy resources (from ${{ github.workflow }} run # ${{ github.run_number }})"
PR_TITLE="Generate deploy resources (from ${{ github.workflow }} run # ${{ github.run_number }})"
PR_BODY="Generated deployment resource changes from [${{ github.workflow }} run # ${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}), which was triggered by commit ${{ env.REF }}."
# Check for changes in deploy resource files
git add \
'**/deploy/k8s/*.yml' \
'deploy/k8s/*.yml' \
'**/deploy/docker-compose/*.yml' \
'deploy/docker-compose/*.yml' \
'deploy/db-init/**'
if git diff --cached --quiet; then
echo "No deploy resource changes detected"
echo "pr_number=" >> $GITHUB_OUTPUT
exit 0
fi
# Configure git and create branch
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b "${PR_BRANCH}"
git commit -m "${COMMIT_MSG}"
git push --set-upstream origin "${PR_BRANCH}"
# Create the PR
PR_URL=$(gh pr create \
--base "${{ env.BRANCH }}" \
--title "${PR_TITLE}" \
--body "${PR_BODY}" \
--label "Generated Resources")
PR_NUMBER=$(echo "${PR_URL}" | grep -o '[0-9]*$')
echo "pr_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "pr_branch=${PR_BRANCH}" >> $GITHUB_OUTPUT
- name: Merge PR
if: steps.create-pr.outputs.pr_number
env:
GH_TOKEN: ${{ secrets.DEPENDABOT_AUTOMERGE_TOKEN }}
run: gh pr merge --squash --delete-branch --admin ${{ steps.create-pr.outputs.pr_number }}