From 9a346e49e3e3a9e60e0fef18b13a00160d849f24 Mon Sep 17 00:00:00 2001 From: Zhigang Wang Date: Sun, 17 May 2026 12:50:08 +0200 Subject: [PATCH 1/2] Add release workflow with tag/release existence checks --- .github/workflows/ci.yml | 6 +--- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5c888ff..b77e5d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,4 @@ jobs: java-version: 8 distribution: temurin cache: maven - - run: mvn -B package - - uses: actions/upload-artifact@v4 - with: - name: pathfinder-java8 - path: target/pathfinder-1.0.jar + - run: mvn -B verify diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6f4b5e6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version (e.g., 1.1)' + required: true + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check if tag already exists + run: | + if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then + echo "::error::Tag v${{ inputs.version }} already exists. Aborting." + exit 1 + fi + + - name: Check if release already exists + env: + GH_TOKEN: ${{ github.token }} + run: | + if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then + echo "::error::Release v${{ inputs.version }} already exists. Aborting." + exit 1 + fi + + - uses: actions/setup-java@v4 + with: + java-version: 8 + distribution: temurin + cache: maven + + - run: mvn -B package + + - name: Create and push tag + run: | + git tag "v${{ inputs.version }}" + git push origin "v${{ inputs.version }}" + + - name: Create release + env: + GH_TOKEN: ${{ github.token }} + run: | + VERSION="${{ inputs.version }}" + gh release create "v$VERSION" \ + target/pathfinder-1.0.jar \ + --title "v$VERSION" \ + --generate-notes \ + --target "${{ github.ref_name }}" From 9aee713e5d9dd7cc8a658ebc133b20ae151b2197 Mon Sep 17 00:00:00 2001 From: Zhigang Wang Date: Sun, 17 May 2026 12:58:03 +0200 Subject: [PATCH 2/2] Read version from pom.xml instead of manual input --- .github/workflows/release.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6f4b5e6..d8b9688 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,10 +2,6 @@ name: Release on: workflow_dispatch: - inputs: - version: - description: 'Release version (e.g., 1.1)' - required: true jobs: release: @@ -15,10 +11,15 @@ jobs: with: fetch-depth: 0 + - name: Get version from pom.xml + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "VERSION=$VERSION" >> $GITHUB_ENV + - name: Check if tag already exists run: | - if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then - echo "::error::Tag v${{ inputs.version }} already exists. Aborting." + if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then + echo "::error::Tag v${{ env.VERSION }} already exists. Aborting." exit 1 fi @@ -26,8 +27,8 @@ jobs: env: GH_TOKEN: ${{ github.token }} run: | - if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then - echo "::error::Release v${{ inputs.version }} already exists. Aborting." + if gh release view "v${{ env.VERSION }}" >/dev/null 2>&1; then + echo "::error::Release v${{ env.VERSION }} already exists. Aborting." exit 1 fi @@ -41,16 +42,15 @@ jobs: - name: Create and push tag run: | - git tag "v${{ inputs.version }}" - git push origin "v${{ inputs.version }}" + git tag "v${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" - name: Create release env: GH_TOKEN: ${{ github.token }} run: | - VERSION="${{ inputs.version }}" - gh release create "v$VERSION" \ + gh release create "v${{ env.VERSION }}" \ target/pathfinder-1.0.jar \ - --title "v$VERSION" \ + --title "v${{ env.VERSION }}" \ --generate-notes \ --target "${{ github.ref_name }}"