From a575be722739bf0107f79d1fa3b422230961e5a0 Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Wed, 11 Sep 2024 10:50:55 +0100 Subject: [PATCH] Refactor actions --- .github/workflows/build.yml | 42 +++++++++++++++++++++++++++ .github/workflows/github_release.yml | 23 +++++++++++++++ .github/workflows/maven.yml | 43 ++++++++++++++++++++++++++++ .github/workflows/maven_release.yml | 11 +++++++ .github/workflows/maven_snapshot.yml | 9 ++++++ 5 files changed, 128 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/github_release.yml create mode 100644 .github/workflows/maven.yml create mode 100644 .github/workflows/maven_release.yml create mode 100644 .github/workflows/maven_snapshot.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..540b36a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,42 @@ +name: Run gradle build + +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" + workflow_dispatch: + workflow_call: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v2 + + - name: Build with Gradle + uses: gradle/gradle-build-action@v3 + with: + arguments: build + + - uses: actions/upload-artifact@v4 + with: + path: build/libs/*.jar + name: build + retention-days: 7 diff --git a/.github/workflows/github_release.yml b/.github/workflows/github_release.yml new file mode 100644 index 0000000..f291f04 --- /dev/null +++ b/.github/workflows/github_release.yml @@ -0,0 +1,23 @@ +name: Make draft release + +on: + workflow_dispatch: + +jobs: + build: + name: Run build + uses: ./.github/workflows/build.yml + + release: + needs: build + permissions: + contents: write + runs-on: ubuntu-latest + steps: + + - uses: actions/download-artifact@v4 + + - name: Release + env: + GH_TOKEN: ${{ github.token }} + run: gh release create --draft ${{ github.ref_name }} --title ${{ github.ref_name }} build/*.jar diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..9d65ec8 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,43 @@ +name: Publish to SciJava Maven + +on: + workflow_call: + inputs: + release: + required: false + type: boolean + default: false + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + java-version: '21' + distribution: 'temurin' + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b + + - name: Add release flag if input variable is set + if: ${{ inputs.release }} + shell: bash + run: | + echo "RELEASE_FLAG='-P release=true'" >> $GITHUB_ENV + + - name: Publish snapshot + uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 + with: + arguments: publish -P toolchain=21 $RELEASE_FLAG + env: + MAVEN_USER: ${{ secrets.MAVEN_USER }} + MAVEN_PASS: ${{ secrets.MAVEN_PASS }} + - uses: actions/upload-artifact@v3 + if: ${{ inputs.release }} + with: + name: ${{ github.event.repository.name }}-release-jar + path: build/libs + retention-days: 7 diff --git a/.github/workflows/maven_release.yml b/.github/workflows/maven_release.yml new file mode 100644 index 0000000..5d254f1 --- /dev/null +++ b/.github/workflows/maven_release.yml @@ -0,0 +1,11 @@ +name: Publish release to SciJava Maven + +on: + workflow_dispatch: + +jobs: + build: + name: Publish release + uses: ./.github/workflows/maven.yml + with: + release: true diff --git a/.github/workflows/maven_snapshot.yml b/.github/workflows/maven_snapshot.yml new file mode 100644 index 0000000..28b66bd --- /dev/null +++ b/.github/workflows/maven_snapshot.yml @@ -0,0 +1,9 @@ +name: Publish snapshot to SciJava Maven + +on: + workflow_dispatch: + +jobs: + build: + name: Publish snapshot + uses: ./.github/workflows/maven.yml