Skip to content

Commit bace58b

Browse files
committed
feat: add reusable workflow to be able to release both project and BOM
1 parent a9572ee commit bace58b

File tree

2 files changed

+67
-46
lines changed

2 files changed

+67
-46
lines changed

.github/workflows/release-project-in-dir.yml

+29-19
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,59 @@ name: Release project in specified directory
33
on:
44
workflow_call:
55
inputs:
6-
project-dir:
6+
project_dir:
77
type: string
88
required: true
9-
version-branch:
9+
version_branch:
1010
type: string
1111
required: true
1212

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+
1317
jobs:
1418
publish:
1519
runs-on: ubuntu-latest
1620
steps:
17-
- name: Checkout "${{inputs.version-branch}}" branch
21+
- name: Checkout "${{inputs.version_branch}}" branch
1822
uses: actions/checkout@v3
1923
with:
20-
ref: "${{inputs.version-branch}}"
24+
ref: "${{inputs.version_branch}}"
2125

2226
- name: Set up Java and Maven
2327
uses: actions/setup-java@v3
2428
with:
2529
java-version: 11
2630
distribution: temurin
2731
cache: 'maven'
28-
29-
- name: Move to specified directory
30-
working-directory: ${{inputs.project-dir}}
31-
run: |
32-
echo "Releasing from ${{inputs.project-dir}}"
33-
shell: bash
3432

3533
- name: Change version to release version
3634
# Assume that RELEASE_VERSION will have form like: "v1.0.1". So we cut the "v"
37-
run: mvn ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
35+
run: |
36+
mvn ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit
3837
env:
3938
RELEASE_VERSION: ${{ github.event.release.tag_name }}
4039

40+
- name: Release Maven package
41+
uses: samuelmeuli/action-maven-publish@v1
42+
with:
43+
maven_profiles: "release"
44+
maven_args: ${{ env.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+
4150
# This is separate job because there were issues with git after release step, was not able to commit changes.
4251
update-working-version:
4352
runs-on: ubuntu-latest
44-
if: "success() && !contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
53+
needs: publish
54+
if: "!contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
4555
steps:
4656
- uses: actions/checkout@v3
4757
with:
48-
ref: "${{inputs.version-branch}}"
58+
ref: "${{inputs.version_branch}}"
4959

5060
- name: Set up Java and Maven
5161
uses: actions/setup-java@v3
@@ -60,12 +70,12 @@ jobs:
6070
mvn ${MAVEN_ARGS} -q build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion}-SNAPSHOT versions:commit
6171
git config --local user.email "[email protected]"
6272
git config --local user.name "GitHub Action"
63-
# git commit -m "Set new SNAPSHOT version into pom files." -a
73+
git commit -m "Set new SNAPSHOT version into pom files." -a
6474
env:
6575
RELEASE_VERSION: ${{ github.event.release.tag_name }}
6676

67-
# - name: Push changes to branch
68-
# uses: ad-m/github-push-action@master
69-
# with:
70-
# branch: "${{inputs.version-branch}}"
71-
# github_token: ${{ secrets.GITHUB_TOKEN }}
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

+38-27
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,51 @@ on:
55
release:
66
types: [ released ]
77
jobs:
8-
publish:
8+
9+
prepare-release:
910
runs-on: ubuntu-latest
11+
env:
12+
tmp_version_branch: ''
13+
outputs:
14+
version_branch: ${{ steps.set-version-branch.outputs.version_branch }}
1015
steps:
1116
- if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
12-
run: echo "Matched ${{version-branch}} branch"
13-
env:
14-
version-branch: "v1"
17+
run: |
18+
echo "Setting version_branch to v1"
19+
echo "tmp_version_branch=v1" >> "$GITHUB_ENV"
1520
- if: ${{ startsWith(github.event.release.tag_name, 'v2.' ) }}
16-
run: echo "Matched ${{version-branch}} branch"
17-
env:
18-
version-branch: "v2"
21+
run: |
22+
echo "Setting version_branch to v2"
23+
echo "tmp_version_branch=v2" >> "$GITHUB_ENV"
1924
- if: ${{ startsWith(github.event.release.tag_name, 'v3.' ) }}
20-
run: echo "Matched ${{version-branch}} branch"
21-
env:
22-
version-branch: "v3"
25+
run: |
26+
echo "Setting version_branch to v3"
27+
echo "tmp_version_branch=v3" >> "$GITHUB_ENV"
2328
- if: ${{ startsWith(github.event.release.tag_name, 'v4.' ) }}
24-
run: echo "Matched ${{version-branch}} branch"
25-
env:
26-
version-branch: "main"
27-
- name: Fail if version-branch is not set
28-
if: "version-branch == ''"
2929
run: |
30-
echo "Failed to find appropriate branch to release ${{github.event.release.tag_name}} from"
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"
3136
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"
3240

33-
- name: Release SDK
34-
uses: ./.github/workflows/release-project-in-dir.yml
35-
with:
36-
version-branch: ${{version-branch}}
37-
project-dir: '.'
41+
release-sdk:
42+
needs: prepare-release
43+
uses: ./.github/workflows/release-project-in-dir.yml
44+
secrets: inherit
45+
with:
46+
version_branch: ${{needs.prepare-release.outputs.version_branch}}
47+
project_dir: '.'
3848

39-
- name: Release BOM
40-
uses: ./.github/workflows/release-project-in-dir.yml
41-
with:
42-
version-branch: ${{version-branch}}
43-
project-dir: './operator-framework-bom'
44-
49+
release-bom:
50+
needs: prepare-release
51+
uses: ./.github/workflows/release-project-in-dir.yml
52+
secrets: inherit
53+
with:
54+
version_branch: ${{needs.prepare-release.outputs.version_branch}}
55+
project_dir: './operator-framework-bom'

0 commit comments

Comments
 (0)