-
Notifications
You must be signed in to change notification settings - Fork 12
83 lines (77 loc) · 2.87 KB
/
prep-release.yaml
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
# This workflow prepares a repository for release, it does following:
# - updates specified base images used in the Dockerfile to use the right tags
# - updates specified go dependencies in go.mod file to point to right branches
# - commits the results back to the originating branch
name: Reusable Prepare repository for release
on:
workflow_call:
inputs:
branch_ref:
description: Ref of the branch that triggers this workflow.
type: string
required: true
images_to_update:
description: List of images in the Dockerfile to update formatted as a JSON array string e.g. '["quay.io/konveyor/analyzer-lsp"]'.
type: string
required: false
default: '[]'
go_deps_to_update:
description: List of go dependencies to update in go.mod file formatterd as a JSON array string e.g. '["github.com/konveyor/analyzer-lsp"]'.
type: string
required: false
default: '[]'
dockerfile:
description: Relative path to Dockefile.
type: string
required: false
default: ./Dockerfile
jobs:
prep-for-release:
runs-on: ubuntu-latest
steps:
- name: Extract version and branch name
id: extract-info
run: |
if [[ "${BRANCH_REF}" =~ ^refs/heads/release-[0-9]+.[0-9]+$ ]]; then
BRANCH="${BRANCH_REF##refs/heads/}"
echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT"
else
echo "branch=NOOP" >> "$GITHUB_OUTPUT"
fi
env:
BRANCH_REF: ${{ inputs.branch_ref }}
- name: Checkout repository
if: steps.extract-info.outputs.branch != 'NOOP'
uses: actions/checkout@v4
- name: Update tags of base images in Dockerfile
if: steps.extract-info.outputs.branch != 'NOOP'
run: |
for IMAGE in $(echo "$REPLACE_IMAGES" | jq -r '.[]'); do
sed -i "s,${IMAGE}.*$,${IMAGE}:${TAG}," "${DOCKERFILE}"
done
env:
REPLACE_IMAGES: ${{ inputs.images_to_update }}
DOCKERFILE: ${{ inputs.dockerfile }}
TAG: ${{ steps.extract-info.outputs.branch }}
- name: Update dependency versions in go mod file
if: steps.extract-info.outputs.branch != 'NOOP'
run: |
for DEP in $(echo "$REPLACE_DEPS" | jq -r '.[]'); do
go get "${DEP}@${BRANCH}"
done
go mod tidy
env:
REPLACE_DEPS: ${{ inputs.go_deps_to_update }}
BRANCH: ${{ steps.extract-info.outputs.branch }}
- name: Commit and push changes
if: steps.extract-info.outputs.branch != 'NOOP'
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add .
git commit -m "prepare for release ${VERSION}"
git push
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GH_USER: ${{ secrets.GH_USER }}
VERSION: ${{ steps.extract-info.outputs.branch }}