-
Notifications
You must be signed in to change notification settings - Fork 1.2k
147 lines (132 loc) · 5.52 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
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
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@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Fetch branch
# this step needs the github repository to be already cloned locally
id: branch_fetch
run: |
if git fetch origin "refs/heads/${{ inputs.branch }}"; then
echo "RESULT=true" >> $GITHUB_OUTPUT
else
echo "RESULT=false" >> $GITHUB_OUTPUT
fi
- name: Checkout branch
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
if: ${{ steps.branch_fetch.outputs.RESULT == 'true' }}
with:
ref: ${{ inputs.branch }}
- name: Setup Python and pip
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
with:
# use Python < 3.12 so that distutil is still available by default
python-version: 3.11
cache: "pip"
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.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 python dependencies
run: |
python3 -m pip install -r requirements.txt
- name: Get current Go version
id: current_go_version
run: |
echo "GO_VERSION=$(inv go-version)" >> $GITHUB_OUTPUT
- name: Get current buildimage tag
id: current_buildimage_tag
run: |
echo "BUILDIMAGE_TAG=$(inv pipeline.get-gitlab-config-image-tag)" >> $GITHUB_OUTPUT
- name: Update buildimages IDs and Go version
id: update_build_images
env:
TEST_VERSION_FLAG: ${{ inputs.test_version && '--test-version' || '--no-test-version' }}
INCLUDE_OTEL_MODULES: ${{ inputs.include_otel_modules && '--include-otel-modules' || '' }}
run: |
if [ "${{ steps.current_go_version.outputs.GO_VERSION }}" = "${{ inputs.go_version }}" ]; then
inv -e buildimages.update --image-tag ${{ inputs.images_id }} $TEST_VERSION_FLAG
echo 'MESSAGE=Update buildimages ID to ${{ inputs.images_id }}' >> $GITHUB_OUTPUT
else
inv -e update-go --image-tag ${{ inputs.images_id }} $TEST_VERSION_FLAG $INCLUDE_OTEL_MODULES -v "${{ inputs.go_version }}"
echo 'MESSAGE=Update Go version to ${{ inputs.go_version }}' >> $GITHUB_OUTPUT
fi
- uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
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 }}
run: |
base_branch=${{ github.ref }} # Get the full ref
base_branch=${base_branch#refs/heads/} # Remove 'refs/heads/' from the ref
# prs variable contains the number of PRs already created that match head and base branches
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--head ${{ inputs.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-shared-components"
run: |
inv -e buildimages.generate-pr-body \ # Generate the PR description
${{ steps.current_buildimage_tag.outputs.BUILDIMAGE_TAG }} \
${{ inputs.images_id }} \
${{ steps.current_go_version.outputs.GO_VERSION }} \
${{ inputs.go_version }} \
${{ inputs.test_version && '--test-version' || '' }} > $TMP_PR_BODY_PATH
gh pr create \ # Create the PR
--base ${{ github.ref }} \
--title $PR_TITLE \
--body-file $TMP_PR_BODY_PATH \
--label $PR_LABELS \
--draft \