1- # .github/workflows/release.yml
21name : Release
32
43on :
5- push :
6- tags :
7- - ' *' # Trigger on any tag push
4+ workflow_dispatch :
85
96concurrency :
107 group : release-${{ github.ref }}
118 cancel-in-progress : true
129
13-
1410jobs :
15- # 1. Reuse the core build-and-test workflow
16- build-and-test :
17- uses : ./.github/workflows/build-and-test.yml
18- with :
19- java-version : ' 21'
20- python-version : ' 3.11'
21-
22- # 2. Release job — runs only if build/test succeeds
23- release :
24- needs : build-and-test
11+ tag :
2512 runs-on : ubuntu-latest
13+ outputs :
14+ tag_name : ${{ steps.set_tag.outputs.tag_name }}
15+ dsl_version : ${{ steps.get_dsl_version.outputs.dsl_version }}
16+ artifact_id : ${{ steps.get_artifact_id.outputs.artifact_id }}
2617 steps :
27- - name : Get tag name
28- id : get_tag
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+ with :
21+ fetch-depth : 0
22+
23+ - name : Set up Java
24+ uses : actions/setup-java@v4
25+ with :
26+ distribution : temurin
27+ java-version : 21
28+ cache : maven
29+
30+ - name : Get DSL version from pom.xml
31+ id : get_dsl_version
32+ run : |
33+ DSL_VERSION=$(mvn help:evaluate -Dexpression=rosetta.dsl.version -q -DforceStdout)
34+ echo "dsl_version=$DSL_VERSION" >> $GITHUB_OUTPUT
35+
36+ - name : Get artifactId from pom.xml
37+ id : get_artifact_id
2938 run : |
30- TAG_NAME=${GITHUB_REF#refs/tags/}
31- RELEASE_VERSION=${TAG_NAME#rosetta-dsl-v}
32- echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
33- echo "release_version=$RELEASE_VERSION" >> $GITHUB_OUTPUT
39+ ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
40+ echo "artifact_id=$ARTIFACT_ID" >> $GITHUB_OUTPUT
41+
42+ - name : Fetch all tags
43+ run : git fetch --tags
3444
45+ - name : Determine next tag
46+ id : set_tag
47+ run : |
48+ DSL_VERSION="${{ steps.get_dsl_version.outputs.dsl_version }}"
49+ TAGS=$(git tag --list "${DSL_VERSION}.*" | sort -V)
50+ if [ -z "$TAGS" ]; then
51+ NEXT_TAG="${DSL_VERSION}.0"
52+ else
53+ MAX_N=$(echo "$TAGS" | sed "s/^${DSL_VERSION}\.//" | sort -n | tail -1)
54+ NEXT_N=$((MAX_N + 1))
55+ NEXT_TAG="${DSL_VERSION}.${NEXT_N}"
56+ fi
57+ echo "tag_name=$NEXT_TAG" >> $GITHUB_OUTPUT
58+
59+ - name : Create and push tag
60+ env :
61+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
62+ run : |
63+ TAG_NAME="${{ steps.set_tag.outputs.tag_name }}"
64+ if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
65+ echo "Tag $TAG_NAME already exists. Exiting."
66+ exit 1
67+ fi
68+ git config user.name "github-actions[bot]"
69+ git config user.email "github-actions[bot]@users.noreply.github.com"
70+ git tag "$TAG_NAME"
71+ git push origin "$TAG_NAME"
72+
73+ build-and-release :
74+ needs : tag
75+ runs-on : ubuntu-latest
76+ steps :
3577 - name : Checkout code
3678 uses : actions/checkout@v4
3779 with :
@@ -44,15 +86,39 @@ jobs:
4486 java-version : 21
4587 cache : maven
4688
47- - name : Build Release Artifacts
89+ - name : Save original pom.xml
90+ run : cp pom.xml pom.xml.bak
91+
92+ - name : Update pom.xml version to match tag
93+ run : |
94+ mvn -B versions:set -DnewVersion=${{ needs.tag.outputs.tag_name }}
95+ mvn -B versions:commit
96+
97+ - name : Build JARs
4898 run : mvn -B clean package
4999
100+ - name : Revert pom.xml to original
101+ run : mv pom.xml.bak pom.xml
102+
103+ - name : Archive JARs
104+ id : archive
105+ run : |
106+ ARTIFACT_ID="${{ needs.tag.outputs.artifact_id }}"
107+ TAG_NAME="${{ needs.tag.outputs.tag_name }}"
108+ JAR="target/${ARTIFACT_ID}-${TAG_NAME}.jar"
109+ JAVADOC_JAR="target/${ARTIFACT_ID}-${TAG_NAME}-javadoc.jar"
110+ echo "jar_path=$JAR" >> $GITHUB_OUTPUT
111+ echo "javadoc_jar_path=$JAVADOC_JAR" >> $GITHUB_OUTPUT
112+
50113 - name : Create GitHub Release
51114 uses : softprops/action-gh-release@v2
52115 with :
53- tag_name : ${{ steps.get_tag .outputs.tag_name }}
54- name : Release ${{ steps.get_tag .outputs.release_version }}
116+ tag_name : ${{ needs.tag .outputs.tag_name }}
117+ name : Release ${{ needs.tag .outputs.tag_name }}
55118 body : |
56- Automated release for version ${{ steps.get_tag.outputs.release_version }}
119+ Automated release for DSL version ${{ needs.tag.outputs.dsl_version }}
120+ files : |
121+ ${{ steps.archive.outputs.jar_path }}
122+ ${{ steps.archive.outputs.javadoc_jar_path }}
57123 env :
58- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments