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

Add release script that reacts on tags like v2.0.0 #336

Merged
merged 6 commits into from
Nov 29, 2023

Conversation

PattaFeuFeu
Copy link
Collaborator

Description

Closes #314

Adds a GitHub Actions script for releasing new versions of this library.

The action is triggered by tag pushes that are formatted like v2.0.0 (could also be v2.0.0-rc1 as long as we have v` and a major, minor, patch version, separated by a dot).

The action first runs gradle check. If that finishes successfully, we continue. If it doesn’t, the build fails.

After check, it runs assemble generatePomFileForBigbonePublication to assemble JAR variants (the same ones that would also be published) and a POM file.

Afterwards, it runs publish to run maven-publish with the configuration in bigbone.library-conventions.gradle.

It then zips the JAR files and POM file into an archive named like BigBone-v2.0.0-20231105.182643.zip.

Finally, a GitHub release is created with the ZIP attached. Release notes are created automatically.
The release is set to pre-release and draft so that we can have a last look or add additional information before we actually publish.

What still needs to be done

It’s currently unclear to me which signing config parameters are necessary. We will need to add secrets to GitHub and reference them in the script so that we pipe them into the necessary gradle steps that need them.

Type of Change

(Keep the one that applies, remove the rest)

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

I ran most of the gradle calls locally, and tested the bash script locally. Since I do not have the necessary signing config properties on my machine, I couldn’t test it completely unfortunately.

Mandatory Checklist

  • My change follows the projects coding style
  • I ran gradle check and there were no errors reported
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • KDoc added to all public methods

@PattaFeuFeu PattaFeuFeu added enhancement New feature or request pipeline CI/CD topics github_actions Pull requests that update GitHub Actions code labels Nov 5, 2023
@PattaFeuFeu PattaFeuFeu self-assigned this Nov 5, 2023
@andregasser
Copy link
Owner

Hey there!

Thanks for preparing this. I have done some research and I think what we should do is something like this:

release.yml

We should change this

- name: Publish the library
  uses: gradle/gradle-build-action@v2
  with:
    arguments: publish

into this:

- name: Publish the library
  uses: gradle/gradle-build-action@v2
  with:
    arguments: publish
  env:  
    SONATYPE_USERNAME: ${{ secrets.OSS_SONATYPE_USERNAME }}
    SONATYPE_PASSWORD: ${{ secrets.OSS_SONATYPE_PASSWORD }}
    ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.SIGNING_KEY_ID }}
    ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_PRIVATE_KEY }}
    ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}

This injects GitHub secrets I have set up as environment variables into this GitHub action, so that Gradle can access it. Naming of the ORG_GRADLE_PROJECT_* vars is according to the Gradle Signing plugin documentation.

bigbone.library-conventions.gradle

Change this:

credentials {
    username = project.properties.containsKey("sonatypeUsername") ? sonatypeUsername : ""
    password = project.properties.containsKey("sonatypePassword") ? sonatypePassword : ""
}

into this:

credentials {
    username = System.getenv("SONATYPE_USERNAME") ?: ""
    password = System.getenv("SONATYPE_PASSWORD") ?: ""
}

Doing so, we instruct Gradle to read credentials needed for Maven Central publishing from environment variables instead from Gradle properties.

Then, in the same file, we would need to change this as well:

signing {
    sign publishing.publications.bigbone
}

into this:

signing {
    def signingKeyId = findProperty("signingKeyId")
    def signingKey = findProperty("signingKey")
    def signingPassword = findProperty("signingPassword")
    useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)  
    sign publishing.publications.bigbone
}

This instructs Gradle to process an ascii-armored privatae key for signing. This process is also documented in the Gradle Signing plugin documentation.

Does that make sense to you? What do you think?

@PattaFeuFeu
Copy link
Collaborator Author

@andregasser All of that sounds like what I had planned anyway. I just didn’t know how your current signing setup worked exactly so I lacked the knowledge about which specific keys would need to be set.

@PattaFeuFeu PattaFeuFeu marked this pull request as ready for review November 26, 2023 12:11
@PattaFeuFeu
Copy link
Collaborator Author

@andregasser I have implemented your suggestions as you wrote them. 😊 Ready for review now.

@andregasser
Copy link
Owner

andregasser commented Nov 28, 2023

Hello @PattaFeuFeu,

This looks good to me and we can merge this.

But: Whenever we create a tag like v2.0.0 to trigger a release, we must set the BigBone version in libs.versions.toml beforehand to 2.0.0 as well, as otherwise the publish will target the wrong repository (snapshots instead of releases - see see bigbone.library-conventions.gradle for details). But I think we can handle this.

It would be nice if we could also build another workflow file for publishing snapshots to Maven Central. What about creating a second file snapshot.yml? It is actually the same as release.yml but in this case the workflow is not triggered via tag creation, but is only executed manually when needed. Same here, the version in libs.versions.toml needs to be set to something like X.Y.Z-SNAPSHOT before running the workflow.

What do you think of this?

Copy link
Owner

@andregasser andregasser left a comment

Choose a reason for hiding this comment

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

👍

@PattaFeuFeu
Copy link
Collaborator Author

But: Whenever we create a tag like v2.0.0 to trigger a release, we must set the BigBone version in libs.versions.toml beforehand to 2.0.0 as well, as otherwise the publish will target the wrong repository (snapshots instead of releases - see see bigbone.library-conventions.gradle for details). But I think we can handle this.

That flow has worked for me for some time now in a different project. We often create a commit with the updated version and tag that commit then.
We could also update the flow to update that file based on what the version in the tag is, but that would be a more involved script. I’d like to try this approach here out first. 😊

It would be nice if we could also build another workflow file for publishing snapshots to Maven Central. What about creating a second file snapshot.yml? It is actually the same as release.yml but in this case the workflow is not triggered via tag creation, but is only executed manually when needed. Same here, the version in libs.versions.toml needs to be set to something like X.Y.Z-SNAPSHOT before running the workflow.

What do you think of this?

We could just reuse this script and additionally add on: workflow_dispatch: as one of the potential triggers. This way, we’ll get a branch picker in the actions for this action.

I can add that to this PR before we merge?

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

Merging #336 (f2d2eea) into master (83ca484) will not change coverage.
Report is 1 commits behind head on master.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #336   +/-   ##
=========================================
  Coverage     47.29%   47.29%           
  Complexity      498      498           
=========================================
  Files           136      136           
  Lines          3673     3673           
  Branches        240      240           
=========================================
  Hits           1737     1737           
  Misses         1755     1755           
  Partials        181      181           

Copy link
Owner

@andregasser andregasser left a comment

Choose a reason for hiding this comment

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

👍

@andregasser
Copy link
Owner

We could just reuse this script and additionally add on: workflow_dispatch: as one of the potential triggers. This way, we’ll get a branch picker in the actions for this action.

Great idea, sure let's do it like that. 😊

@andregasser andregasser merged commit 8d8da41 into master Nov 29, 2023
5 checks passed
@andregasser andregasser deleted the feature/#314/github-action-release-workflow branch November 29, 2023 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request github_actions Pull requests that update GitHub Actions code pipeline CI/CD topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build a GitHub Actions bases workflow to release the library (snapshots and releases)
2 participants