forked from NationalSecurityAgency/emissary
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (68 loc) · 2.52 KB
/
create-patch-branch.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
---
name: "Create a Patch Branch"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
inputs:
cherrypick_commits:
description: "List of space delimited commits to cherry pick"
required: false
default: ""
env:
JAVA_VERSION: "11"
JAVA_DISTRIBUTION: "corretto"
jobs:
verify:
runs-on: ubuntu-latest
steps:
- name: Check patch release type is using correct branch
if: ${{ !startsWith(github.ref_name, 'release/') }}
run: |
echo "Cannot create a patch branch, please target a branch the starts with 'release/'"
exit 1
patch:
needs: verify
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
branch: ${{ steps.set_output.outputs.patch_branch }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up JDK ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: ${{ env.JAVA_DISTRIBUTION }}
cache: "maven"
- name: Configure Git user
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
- name: Get the version
run: |
echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '\[.*' )" >> "$GITHUB_ENV"
echo "PATCH_BRANCH=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | grep -v '\[.*' | awk -F. '{print "patch/"$1"."$2".x"}')" >> "$GITHUB_ENV"
- id: set_output
run: echo "patch_branch=${{ env.PATCH_BRANCH }}" >> "$GITHUB_OUTPUT"
- name: Fail for milestone versions
if: ${{ contains(env.PROJECT_VERSION, '-M') }}
run: |
echo "Cannot create a patch branch on a milestone release"
exit 1
- name: Branch that patch
run: git switch -c ${{ env.PATCH_BRANCH }}
- name: Set the patch version
run: |
mvn -B -V -e -ntp versions:set -DnextSnapshot=true
mvn -B -V -e -ntp versions:commit
git add .
git commit -m "[github-actions](${{ github.actor }}) prepare for next patch iteration"
git push -u origin ${{ env.PATCH_BRANCH }}
cherry_pick:
if: ${{ github.event.inputs.cherrypick_commits != '' }}
needs: patch
uses: ./.github/workflows/cherrypick.yml
with:
branch: ${{ needs.patch.outputs.branch }}
commits: ${{ github.event.inputs.cherrypick_commits }}