diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2c780b8..9fd10fa 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -34,7 +34,7 @@ jobs: ./gradlew # (load the gradle wrapper, required for the get version step) echo "version=$(./gradlew :model:printVersion --console=plain -q)" >> $GITHUB_OUTPUT - - name: Version verification + - name: Release version verification run: | if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then echo "Release interrupted: DDI Lifecycle lib version '${{ steps.version-step.outputs.version }}' is not in correct format X.Y.Z" diff --git a/.github/workflows/snapshot.yaml b/.github/workflows/snapshot.yaml new file mode 100644 index 0000000..5d34451 --- /dev/null +++ b/.github/workflows/snapshot.yaml @@ -0,0 +1,112 @@ +name: Publish snapshot + +on: + pull_request: + types: [labeled] + +env: + JAVA_VERSION: '17' + +jobs: + + check-version: + if: ${{ contains(github.event.pull_request.labels.*.name, 'publish-snapshot') }} + runs-on: ubuntu-latest + outputs: + snapshot-version: ${{ steps.version-step.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: ${{ env.JAVA_VERSION }} + + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 + + - name: Get DDI-Lifecycle lib version + id: version-step + run: | + ./gradlew # (load the gradle wrapper, required for the get version step) + echo "version=$(./gradlew :model:printVersion --console=plain -q)" >> $GITHUB_OUTPUT + + - name: Snapshot version verification + run: | + if ! [[ "${{ steps.version-step.outputs.version }}" =~ ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT$ ]]; then + echo "Snapshot interrupted: DDI Lifecycle lib version '${{ steps.version-step.outputs.version }}' is not in correct format X.Y.Z-SNAPSHOT" + exit 1 + fi + + - name: Check tag existence + uses: mukunku/tag-exists-action@v1.5.0 + id: check-tag-exists + with: + tag: ${{ steps.version-step.outputs.version }} + + - name: Tag verification + run: | + if [[ "${{ steps.check-tag-exists.outputs.exists }}" == "true" ]]; then + echo "Snapshot interrupted: tag '${{ steps.version-step.outputs.version }}' already exists." + exit 1 + fi + + publish-snapshot: + needs: check-version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: ${{ env.JAVA_VERSION }} + + - name: Setup Gradle + uses: gradle/gradle-build-action@v3 + + - name: Publish DDI Lifecycle lib on Maven Central + run: | + ./gradlew :model:publish + env: + OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} + OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + + write-comment: + needs: [check-version, publish-snapshot] + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '👋 Version ${{ needs.check-version.outputs.snapshot-version }} published on maven central repository' + }) + + create-tag: + needs: [check-version, publish-snapshot] + runs-on: ubuntu-latest + steps: + - name: Create tag + uses: actions/github-script@v7 + with: + script: | + github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'refs/tags/${{ needs.check-version.outputs.snapshot-version }}', + sha: context.sha + }) + + remove-publish-label: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: 'publish-snapshot' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 226b262..da5fb5d 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,6 +12,7 @@ env: jobs: test: + if: ${{ (github.event.pull_request.draft == false) && !contains(github.event.pull_request.labels.*.name, 'publish-snapshot') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/model/build.gradle.kts b/model/build.gradle.kts index 45ae923..51f395c 100644 --- a/model/build.gradle.kts +++ b/model/build.gradle.kts @@ -26,7 +26,7 @@ java { } group = "fr.insee.ddi" -version = "1.0.0-SNAPSHOT" +version = "1.0.0" val nameForArtifactAndJar by extra("ddi-lifecycle") repositories { @@ -123,9 +123,9 @@ publishing { repositories { maven { val isSnapshot: Boolean = version.toString().endsWith("SNAPSHOT") - val snapshotRepo2: URI = URI.create("https://s01.oss.sonatype.org/content/repositories/snapshots/") - val releaseRepo2: URI = URI.create("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") - val mavenRepo: URI = if (isSnapshot) snapshotRepo2 else releaseRepo2 + val snapshotRepo: URI = URI.create("https://oss.sonatype.org/content/repositories/snapshots/") + val releaseRepo: URI = URI.create("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + val mavenRepo: URI = if (isSnapshot) snapshotRepo else releaseRepo val commandLineRepoUrl = System.getProperty("repoUrl")