Skip to content

Commit 3b6806a

Browse files
committed
feat: add reusable release workflow and use it to also release BOM
Getting variables passed around properly is difficult to get right! :(
1 parent e6cc412 commit 3b6806a

File tree

2 files changed

+122
-96
lines changed

2 files changed

+122
-96
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release project in specified directory
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
project_dir:
7+
type: string
8+
required: true
9+
version_branch:
10+
type: string
11+
required: true
12+
13+
env:
14+
# set the target pom to use the input directory as root
15+
MAVEN_ARGS: -V -ntp -e -f ${{ inputs.project_dir }}/pom.xml
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout "${{inputs.version_branch}}" branch
22+
uses: actions/checkout@v3
23+
with:
24+
ref: "${{inputs.version_branch}}"
25+
26+
- name: Set up Java and Maven
27+
uses: actions/setup-java@v3
28+
with:
29+
java-version: 11
30+
distribution: temurin
31+
cache: 'maven'
32+
33+
- name: Change version to release version
34+
# Assume that RELEASE_VERSION will have form like: "v1.0.1". So we cut the "v"
35+
run: |
36+
mvn ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
37+
env:
38+
RELEASE_VERSION: ${{ github.event.release.tag_name }}
39+
40+
- name: Release Maven package
41+
uses: samuelmeuli/action-maven-publish@v1
42+
with:
43+
maven_profiles: "release"
44+
maven_args: "${MAVEN_ARGS}"
45+
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
46+
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
47+
nexus_username: ${{ secrets.OSSRH_USERNAME }}
48+
nexus_password: ${{ secrets.OSSRH_TOKEN }}
49+
50+
# This is separate job because there were issues with git after release step, was not able to commit changes.
51+
update-working-version:
52+
runs-on: ubuntu-latest
53+
needs: publish
54+
if: "!contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
55+
steps:
56+
- uses: actions/checkout@v3
57+
with:
58+
ref: "${{inputs.version_branch}}"
59+
60+
- name: Set up Java and Maven
61+
uses: actions/setup-java@v3
62+
with:
63+
java-version: 11
64+
distribution: temurin
65+
cache: 'maven'
66+
67+
- name: Change version to release version
68+
run: |
69+
mvn ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
70+
mvn ${MAVEN_ARGS} -q build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-SNAPSHOT versions:commit
71+
git config --local user.email "[email protected]"
72+
git config --local user.name "GitHub Action"
73+
git commit -m "Set new SNAPSHOT version into pom files." -a
74+
env:
75+
RELEASE_VERSION: ${{ github.event.release.tag_name }}
76+
77+
- name: Push changes to branch
78+
uses: ad-m/github-push-action@master
79+
with:
80+
branch: "${{inputs.version_branch}}"
81+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 41 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,104 +5,49 @@ on:
55
release:
66
types: [ released ]
77
jobs:
8-
publish:
9-
runs-on: ubuntu-latest
10-
steps:
11-
- uses: actions/checkout@v3
12-
if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
13-
with:
14-
ref: "v1"
15-
- uses: actions/checkout@v3
16-
if: ${{ startsWith(github.event.release.tag_name, 'v2.') }}
17-
with:
18-
ref: "v2"
19-
- uses: actions/checkout@v3
20-
if: ${{ startsWith(github.event.release.tag_name, 'v3.') }}
21-
with:
22-
ref: "v3"
23-
- uses: actions/checkout@v3
24-
if: ${{ startsWith(github.event.release.tag_name, 'v4.') }}
25-
- name: Set up Java and Maven
26-
uses: actions/setup-java@v3
27-
with:
28-
java-version: 11
29-
distribution: temurin
30-
cache: 'maven'
31-
- name: change version to release version
32-
# Assume that RELEASE_VERSION will have form like: "v1.0.1". So we cut the "v"
33-
run: ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
34-
env:
35-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
36-
- name: change version to release version for bom module
37-
working-directory: ./operator-framework-bom
38-
run: ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
39-
env:
40-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
41-
- name: Release Maven package
42-
uses: samuelmeuli/action-maven-publish@v1
43-
with:
44-
maven_profiles: "release"
45-
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
46-
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
47-
nexus_username: ${{ secrets.OSSRH_USERNAME }}
48-
nexus_password: ${{ secrets.OSSRH_TOKEN }}
49-
508

51-
# This is separate job because there were issues with git after release step, was not able to commit changes. See history.
52-
update-working-version:
9+
prepare-release:
5310
runs-on: ubuntu-latest
54-
if: "!contains(github.event.release.tag_name, 'RC')"
11+
env:
12+
tmp_version_branch: ''
13+
outputs:
14+
version_branch: ${{ steps.set-version-branch.outputs.version_branch }}
5515
steps:
56-
- uses: actions/checkout@v3
57-
if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
58-
with:
59-
ref: "v1"
60-
- uses: actions/checkout@v3
61-
if: ${{ startsWith(github.event.release.tag_name, 'v2.') }}
62-
with:
63-
ref: "v2"
64-
- uses: actions/checkout@v3
65-
if: ${{ startsWith(github.event.release.tag_name, 'v3.') }}
66-
with:
67-
ref: "v3"
68-
- uses: actions/checkout@v3
69-
if: ${{ startsWith(github.event.release.tag_name, 'v4.') }}
70-
- name: Set up Java and Maven
71-
uses: actions/setup-java@v3
72-
with:
73-
java-version: 11
74-
distribution: temurin
75-
cache: 'maven'
76-
- name: change version to release version
16+
- if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
17+
run: |
18+
echo "Setting version_branch to v1"
19+
echo "tmp_version_branch=v1" >> "$GITHUB_ENV"
20+
- if: ${{ startsWith(github.event.release.tag_name, 'v2.' ) }}
21+
run: |
22+
echo "Setting version_branch to v2"
23+
echo "tmp_version_branch=v2" >> "$GITHUB_ENV"
24+
- if: ${{ startsWith(github.event.release.tag_name, 'v3.' ) }}
7725
run: |
78-
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
79-
./mvnw ${MAVEN_ARGS} -q build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-SNAPSHOT versions:commit
80-
git config --local user.email "[email protected]"
81-
git config --local user.name "GitHub Action"
82-
git commit -m "Set new SNAPSHOT version into pom files." -a
83-
env:
84-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
85-
- name: Push changes v1
86-
uses: ad-m/github-push-action@master
87-
if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
88-
with:
89-
github_token: ${{ secrets.GITHUB_TOKEN }}
90-
branch: "v1"
91-
- name: Push changes v2
92-
uses: ad-m/github-push-action@master
93-
if: ${{ startsWith(github.event.release.tag_name, 'v2.' ) }}
94-
with:
95-
github_token: ${{ secrets.GITHUB_TOKEN }}
96-
branch: "v2"
97-
- name: Push changes v3
98-
uses: ad-m/github-push-action@master
99-
if: ${{ startsWith(github.event.release.tag_name, 'v3.' ) }}
100-
with:
101-
github_token: ${{ secrets.GITHUB_TOKEN }}
102-
branch: "v3"
103-
- name: Push changes v4
104-
uses: ad-m/github-push-action@master
105-
if: ${{ startsWith(github.event.release.tag_name, 'v4.' ) }}
106-
with:
107-
github_token: ${{ secrets.GITHUB_TOKEN }}
26+
echo "Setting version_branch to v3"
27+
echo "tmp_version_branch=v3" >> "$GITHUB_ENV"
28+
- if: ${{ startsWith(github.event.release.tag_name, 'v4.' ) }}
29+
run: |
30+
echo "Setting version_branch to main"
31+
echo "tmp_version_branch=main" >> "$GITHUB_ENV"
32+
- if: ${{ env.tmp_version_branch == '' }}
33+
name: Fail if version_branch is not set
34+
run: |
35+
echo "Failed to find appropriate branch to release ${{github.event.release.tag_name}} from"
36+
exit 1
37+
- id: set-version-branch
38+
name: Set version_branch if matched
39+
run: echo "::set-output name=version_branch::$tmp_version_branch"
40+
41+
release-sdk:
42+
needs: prepare-release
43+
uses: ./.github/workflows/release-project-in-dir.yml
44+
with:
45+
version_branch: ${{needs.prepare-release.outputs.version_branch}}
46+
project_dir: '.'
10847

48+
release-bom:
49+
needs: prepare-release
50+
uses: ./.github/workflows/release-project-in-dir.yml
51+
with:
52+
version_branch: ${{needs.prepare-release.outputs.version_branch}}
53+
project_dir: './operator-framework-bom'

0 commit comments

Comments
 (0)