Skip to content

Commit b3ec5e9

Browse files
committed
Update workflows
1 parent 7ba00c8 commit b3ec5e9

File tree

8 files changed

+132
-7
lines changed

8 files changed

+132
-7
lines changed

.github/utils/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# GitHub Actions and its Utilities
2+
3+
## File [`next_version.txt`](next_version.txt)
4+
5+
This file contains planned next version for `-SNAPSHOT` releases. It must match `vX.Y.Z` format and contain single line
6+
with planned version only.
7+
8+
File integrity is validated with [`validate-next_version.txt.yml`](../workflows/validate-next_version.txt.yml) workflow.
9+
10+
Used by [`gradle-publish-snapshot.yml`](../workflows/gradle-publish-snapshot.yml) workflow, which is launched manually.

.github/utils/next_version.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.2.0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Require file via first argument or FILE env variable
5+
FILE="${1:-${FILE:-}}"
6+
7+
if [ ! -f "$FILE" ]; then
8+
echo "::error::file $FILE not found"
9+
exit 1
10+
fi
11+
12+
# Read file and trim whitespaces
13+
VERSION=$(tr -d '[:space:]' < "$FILE")
14+
15+
# Validate version format
16+
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
17+
echo "::error::validation of $FILE failed: '$VERSION', expected format: vX.Y.Z (e.g. v1.2.3)"
18+
exit 1
19+
fi
20+
21+
echo "::notice::validation of $FILE passed: '$VERSION'"

.github/workflows/gradle-build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ name: Gradle Build
33
on:
44
push:
55
branches: [ "main" ]
6+
paths:
7+
- "src/**"
8+
- "build.gradle.kts"
9+
- "settings.gradle.kts"
10+
- "gradle.properties"
11+
- "gradle/**"
12+
- "buildSrc/**"
13+
- "gradlew"
14+
- "gradlew.bat"
15+
- ".github/workflows/gradle-build.yml"
616
pull_request:
717
branches: [ "main" ]
818

.github/workflows/gradle-dependency-submission.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ name: Dependency Submission
33
on:
44
push:
55
branches: [ "main" ]
6-
paths:
7-
- 'build.gradle.kts'
8-
- 'settings.gradle.kts'
9-
- 'gradle/**'
10-
- 'buildSrc/**'
116

127
jobs:
138
dependency-submission:

.github/workflows/gradle-release.yml renamed to .github/workflows/gradle-publish-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Gradle Release
1+
name: Gradle Publish [release]
22

33
on:
44
push:
@@ -33,5 +33,5 @@ jobs:
3333
PUBLISHING_PASSWORD: ${{ secrets.PUBLISHING_PASSWORD }}
3434
run: |
3535
VERSION="${GITHUB_REF_NAME#v}" # removes leading 'v' from tag name
36-
echo "Publishing version $VERSION"
36+
echo "::notice::publishing version $VERSION"
3737
./gradlew -Pversion="$VERSION" -Psign publishAllPublicationsToCentralPortal
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Gradle Publish [snapshot]
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
check-branch:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check Branch
11+
if: github.ref != 'refs/heads/main'
12+
run: |
13+
echo "::error title=wrong branch selected::this workflow must be run on the 'main' branch"
14+
exit 1
15+
16+
publish-snapshot:
17+
needs: check-branch
18+
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v5
23+
with:
24+
ref: main
25+
26+
- name: Set up JDK 17
27+
uses: actions/setup-java@v5
28+
with:
29+
java-version: "17"
30+
distribution: "temurin"
31+
32+
- name: Setup Gradle
33+
uses: gradle/actions/setup-gradle@v4
34+
35+
- name: Evaluate Version
36+
id: version
37+
env:
38+
VERSION_FILE: .github/utils/next_version.txt
39+
run: |
40+
if [ -n "${VERSION_FILE:-}" ] && [ -f "$VERSION_FILE" ]; then
41+
bash .github/utils/validate_version_file.sh "$VERSION_FILE"
42+
NEXT_VERSION=$(cat "$VERSION_FILE" | tr -d '[:space:]') # trim whitespaces
43+
echo "::notice::using version from $VERSION_FILE: $NEXT_VERSION"
44+
else
45+
echo "::error::file $VERSION_FILE not found"
46+
exit 1
47+
fi
48+
49+
NEXT_VERSION="${NEXT_VERSION#v}" # strip leading 'v' if present
50+
SNAPSHOT_VERSION="${NEXT_VERSION}-SNAPSHOT"
51+
52+
echo "::notice::evaluated snapshot version: $SNAPSHOT_VERSION"
53+
echo "version=$SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
54+
55+
- name: Publish Snapshot with Gradle Wrapper
56+
env:
57+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
58+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
59+
PUBLISHING_USERNAME: ${{ secrets.PUBLISHING_USERNAME }}
60+
PUBLISHING_PASSWORD: ${{ secrets.PUBLISHING_PASSWORD }}
61+
run: |
62+
./gradlew -Pversion="${{ steps.version.outputs.version }}" publishAllPublicationsToCentralPortalSnapshots
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Validate [next_version.txt]
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- ".github/utils/next_version.txt"
8+
- ".github/utils/validate_version_file.sh"
9+
- ".github/workflows/validate-next_version.txt.yml"
10+
pull_request:
11+
paths:
12+
- ".github/utils/next_version.txt"
13+
- ".github/utils/validate_version_file.sh"
14+
- ".github/workflows/validate-next_version.txt.yml"
15+
16+
jobs:
17+
validate:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v5
22+
23+
- name: Validate next_version.txt file
24+
env:
25+
FILE: ".github/utils/next_version.txt"
26+
run: bash .github/utils/validate_version_file.sh

0 commit comments

Comments
 (0)