Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: snapshot publish workflow #5

Merged
merged 7 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/snapshot.yaml
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member

@FBibonne FBibonne Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Semver pattern allows richer chains for previous release version or release metadata (https://semver.org/lang/fr/#spec-item-9 and item 10 also). Maybe patterns like ^[0-9]+.[0-9]+.[0-9]+-[0-9A-Za-z-]+$ should be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I quite like enforcing "snapshot" since it has a meaning for maven (snapshots have a different overwrite mechanism), and adding other tags introduces some complexity that often feels not necessary

Yet it is restrictive in regards to semver... so we could use the more complex regex.

Isn't the "+" symbol missing for metadata?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose this pattern : (?>^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT$)|(?>^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT\+[0-9A-Za-z-]+$)

it means that the version must match ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT$ (for example 1.1.1-SNAPSHOT) or must match ^[0-9]+.[0-9]+.[0-9]+-SNAPSHOT\+[0-9A-Za-z-]+$ (for example 1.1.1-SNAPSHOT+feat1). So it is mandatory the version starts with x.y.z-SNAPSHOT and then it may be suffixed by a string wich starts with +

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

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/[email protected]
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'
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")

Expand Down