-
Notifications
You must be signed in to change notification settings - Fork 1.3k
168 lines (152 loc) · 6.17 KB
/
buildimages-update.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: Update buildimages
on:
workflow_dispatch:
inputs:
images_id:
description: 'Images ID'
required: true
type: string
go_version:
description: 'Go version'
required: true
type: string
branch:
description: 'Git branch to use'
required: true
type: string
test_version:
description: 'Whether the images are test images'
required: true
type: boolean
include_otel_modules:
description: 'Whether to also bump the Go version in modules used by OpenTelemetry'
required: true
type: boolean
permissions: {}
jobs:
open-go-update-pr:
runs-on: ubuntu-latest
permissions:
contents: write # push commit and branch
pull-requests: write
steps:
- name: Checkout branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
# credentials are needed to create the PR at the end of the workflow
persist-credentials: true
- name: Fetch branch
env:
TARGET_BRANCH: ${{ inputs.branch }}
# this step needs the github repository to be already cloned locally
id: branch_fetch
run: |
if git fetch origin "refs/heads/$TARGET_BRANCH"; then
echo "RESULT=true" >> $GITHUB_OUTPUT
else
echo "RESULT=false" >> $GITHUB_OUTPUT
fi
- name: Checkout branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
if: ${{ steps.branch_fetch.outputs.RESULT == 'true' }}
with:
ref: ${{ inputs.branch }}
persist-credentials: false
- name: Setup Python and pip
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
with:
python-version-file: .python-version
cache: "pip"
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
# use the go version from the input, not from the .go-version file
# in case it's a Go update PR
go-version: ${{ inputs.go_version }}
- name: Install dda
uses: ./.github/actions/install-dda
with:
features: legacy-tasks
- name: Get current Go version
id: current_go_version
run: |
echo "GO_VERSION=$(dda inv go-version)" >> $GITHUB_OUTPUT
- name: Get current buildimage tag
id: current_buildimage_tag
run: |
echo "BUILDIMAGE_TAG=$(dda inv buildimages.get-tag)" >> $GITHUB_OUTPUT
- name: Update buildimages IDs and Go version
id: update_build_images
env:
TEST_VERSION_FLAG: ${{ inputs.test_version && '--test' || '--no-test' }}
# INCLUDE_OTEL_MODULES must be used without quotes to be ignored when empty
INCLUDE_OTEL_MODULES: ${{ inputs.include_otel_modules && '--include-otel-modules' || '' }}
CURRENT_GO_VERSION: ${{ steps.current_go_version.outputs.GO_VERSION }}
INPUT_GO_VERSION: ${{ inputs.go_version }}
IMAGES_ID: ${{ inputs.images_id }}
run: |
if [ "$CURRENT_GO_VERSION" = "$INPUT_GO_VERSION" ]; then
dda inv -e buildimages.update --tag "$IMAGES_ID" "$TEST_VERSION_FLAG"
echo "MESSAGE=Update buildimages ID to $IMAGES_ID" >> $GITHUB_OUTPUT
else
dda inv -e update-go --image-tag "$IMAGES_ID" "$TEST_VERSION_FLAG" $INCLUDE_OTEL_MODULES -v "$INPUT_GO_VERSION"
echo "MESSAGE=Update Go version to $INPUT_GO_VERSION" >> $GITHUB_OUTPUT
fi
- uses: stefanzweifel/git-auto-commit-action@e348103e9026cc0eee72ae06630dbe30c8bf7a79 # v5.1.0
id: autocommit
with:
commit_message: ${{ steps.update_build_images.outputs.MESSAGE }}
branch: ${{ inputs.branch }}
create_branch: true
# allow empty commits, so that the branch always exists if the workflow succeeds
commit_options: '--allow-empty'
skip_dirty_check: true # prevents pushing an empty commit if false
# the action fetches all branches and tags, in our case the branches we care about are already fetched
# if they exist, so we can skip the fetch
skip_fetch: true
- name: Check if PR exists
id: check_pr
env:
GH_TOKEN: ${{ github.token }}
BASE_BRANCH: ${{ github.ref_name }}
INPUT_BRANCH: ${{ inputs.branch }}
run: |
# prs variable contains the number of PRs already created that match head and base branches
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head "$INPUT_BRANCH" \
--base "$BASE_BRANCH" \
--json title \
--jq 'length')
if [ $prs -eq 0 ]; then
echo "CREATE_PR=true" >> $GITHUB_OUTPUT
fi
# Create PR only if there is no pre-existing PR on the branch
- name: Create PR
if: ${{ steps.check_pr.outputs.CREATE_PR == 'true' }}
env:
TMP_PR_BODY_PATH: /tmp/pr_body
GH_TOKEN: ${{ github.token }}
PR_TITLE: "[automated] ${{ steps.update_build_images.outputs.MESSAGE }}"
PR_LABELS: "go-update,team/agent-runtimes"
CURRENT_BUILDIMAGE_TAG: ${{ steps.current_buildimage_tag.outputs.BUILDIMAGE_TAG }}
IMAGES_ID: ${{ inputs.images_id }}
CURRENT_GO_VERSION: ${{ steps.current_go_version.outputs.GO_VERSION }}
INPUT_GO_VERSION: ${{ inputs.go_version }}
# INPUT_TEST_VERSION must be used without quotes to be ignored when empty
INPUT_TEST_VERSION: ${{ inputs.test_version && '--test' || '' }}
GITHUB_REF: ${{ github.ref }}
run: |
# Generate the PR description
dda inv -e buildimages.generate-pr-body \
"$CURRENT_BUILDIMAGE_TAG" \
"$IMAGES_ID" \
"$CURRENT_GO_VERSION" \
"$INPUT_GO_VERSION" \
$INPUT_TEST_VERSION > $TMP_PR_BODY_PATH
# Create the PR
gh pr create \
--base "$GITHUB_REF" \
--title "$PR_TITLE" \
--body-file "$TMP_PR_BODY_PATH" \
--label "$PR_LABELS" \
--draft \