1+ name : Release
2+
3+ on :
4+ workflow_dispatch :
5+
6+ concurrency :
7+ group : release-${{ github.ref }}
8+ cancel-in-progress : true
9+
10+ jobs :
11+ tag :
12+ 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 }}
17+ steps :
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
38+ run : |
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
44+
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 :
77+ - name : Checkout code
78+ uses : actions/checkout@v4
79+ with :
80+ fetch-depth : 0
81+
82+ - name : Set up Java
83+ uses : actions/setup-java@v4
84+ with :
85+ distribution : temurin
86+ java-version : 21
87+ cache : maven
88+
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
98+ run : mvn -B clean package
99+
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+
113+ - name : Create GitHub Release
114+ uses : softprops/action-gh-release@v2
115+ with :
116+ tag_name : ${{ needs.tag.outputs.tag_name }}
117+ name : ${{ needs.tag.outputs.tag_name }}
118+ body : |
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 }}
123+ env :
124+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments