Skip to content

Commit b881383

Browse files
authored
UID2-2558 Use new commit and push workflow (#56)
1 parent c8a1133 commit b881383

File tree

3 files changed

+67
-45
lines changed

3 files changed

+67
-45
lines changed

.github/workflows/release.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Release
2+
run-name: ${{ format('Release version {0}', inputs.version)}} by @${{ github.actor }}
23

34
on:
45
workflow_dispatch:
@@ -17,18 +18,28 @@ jobs:
1718
runs-on: ubuntu-latest
1819

1920
permissions:
21+
pull-requests: write
2022
contents: write
23+
security-events: write
24+
packages: write
2125

2226
steps:
2327
- name: Checkout
24-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2529

2630
- name: Set up JDK 17
2731
uses: actions/setup-java@v3
2832
with:
2933
java-version: '17'
3034
distribution: 'temurin'
3135

36+
- name: Fail if Release and not on Default branch
37+
if: ${{ github.event.repository.default_branch != github.ref_name }}
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
core.setFailed('Releases can not be created on a feature branch. Branch: ${{ github.ref_name }}')
42+
3243
- name: Update Git user
3344
run: |
3445
git config --local user.name "IABTechLab"
@@ -42,14 +53,47 @@ jobs:
4253
# Disable writing to cache. Don't want to spoil the main cache
4354
cache-read-only: true
4455

45-
- name: Release
46-
run: ./scripts/release.sh ${{ inputs.version }} ${{ inputs.snapshot }}
56+
- name: Get Snaptshot versions
57+
id: snapshotVersions
58+
run: ./scripts/get_snapshot_versions.sh ${{ inputs.snapshot }}
59+
60+
- name: Prepare for release metadata
61+
shell: bash
62+
run: |
63+
sed -i.bak "s/${{ steps.snapshotVersions.outputs.cur_snapshot_version }}/${{ inputs.version }}/g" gradle.properties
64+
65+
- name: Commit gradle.properties and set tag for v${{ inputs.version }}
66+
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
67+
with:
68+
add: 'gradle.properties'
69+
message: 'Prepare for release: ${{ inputs.version }}'
70+
tag: v${{ inputs.version }}
71+
72+
- name: Deploy v${{ inputs.version }}
73+
run: ./gradlew publish
4774
env:
4875
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_REPO_USERNAME }}
4976
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_REPO_PASSWORD }}
5077
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }}
5178
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }}
5279

80+
- name: Prepare next Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}
81+
shell: bash
82+
run: |
83+
echo "Setting next snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}"
84+
sed -i.bak "s/${{ inputs.version }}/${{ steps.snapshotVersions.outputs.new_snapshot_version }}/g" gradle.properties
85+
86+
- name: Commit gradle.properties for Snapshot version ${{ steps.snapshotVersions.outputs.new_snapshot_version }}
87+
uses: IABTechLab/uid2-shared-actions/actions/commit_pr_and_merge@v2
88+
with:
89+
add: 'gradle.properties'
90+
message: 'Prepare next development version: ${{ steps.snapshotVersions.outputs.new_snapshot_version }}'
91+
92+
- name: Remove the backup file from sed edits
93+
shell: bash
94+
run: |
95+
rm gradle.properties.bak
96+
5397
- name: GitHub Release
5498
uses: softprops/action-gh-release@v1
5599
with:

scripts/get_snapshot_versions.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -exo pipefail
4+
5+
# Gets a property out of a .properties file
6+
# usage: getProperty $key $filename
7+
function getProperty() {
8+
grep "${1}" "$2" | cut -d'=' -f2
9+
}
10+
11+
NEW_SNAPSHOT_VERSION=$1
12+
CUR_SNAPSHOT_VERSION=$(getProperty 'VERSION_NAME' gradle.properties)
13+
14+
if [ -z "$NEW_SNAPSHOT_VERSION" ]; then
15+
# If no snapshot version was provided, use the current value
16+
NEW_SNAPSHOT_VERSION=$CUR_SNAPSHOT_VERSION
17+
fi
18+
19+
echo "new_snapshot_version=$NEW_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
20+
echo "cur_snapshot_version=$CUR_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT

scripts/release.sh

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)