From 3231d7b9b4fcd05afff3db32d34aa37565535ccb Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 17 Nov 2023 15:59:15 -0500 Subject: [PATCH] Make Slack notification step optional * Simply some `if:` expressions * Document how to run release workflow * Add `on: schedule:` example * Add warning into docs about nested reusable workflow levels --- .../workflows/spring-artifactory-release.yml | 4 ++-- .github/workflows/spring-finalize-release.yml | 23 ++++++++++--------- .github/workflows/spring-stage-release.yml | 4 ++-- README.md | 14 ++++++++++- samples/schedule-releases.yml | 19 +++++++++++++++ 5 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 samples/schedule-releases.yml diff --git a/.github/workflows/spring-artifactory-release.yml b/.github/workflows/spring-artifactory-release.yml index 3c67f63..c613b3d 100644 --- a/.github/workflows/spring-artifactory-release.yml +++ b/.github/workflows/spring-artifactory-release.yml @@ -20,6 +20,8 @@ on: required: false GRADLE_ENTERPRISE_SECRET_ACCESS_KEY: required: false + SPRING_RELEASE_SLACK_WEBHOOK_URL: + required: false GH_ACTIONS_REPO_TOKEN: required: true OSSRH_URL: @@ -36,8 +38,6 @@ on: required: true JF_ARTIFACTORY_SPRING: required: true - SPRING_RELEASE_SLACK_WEBHOOK_URL: - required: true env: GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} diff --git a/.github/workflows/spring-finalize-release.yml b/.github/workflows/spring-finalize-release.yml index 5f82c67..3b10a25 100644 --- a/.github/workflows/spring-finalize-release.yml +++ b/.github/workflows/spring-finalize-release.yml @@ -10,7 +10,7 @@ on: secrets: SPRING_RELEASE_SLACK_WEBHOOK_URL: - required: true + required: false GH_ACTIONS_REPO_TOKEN: required: true @@ -52,13 +52,14 @@ jobs: gh api -X PATCH repos/$GITHUB_REPOSITORY/milestones/$MILESTONE_ID -f state='closed' --silent fi -# - name: Announce Release on Slack -# uses: slackapi/slack-github-action@v1.24.0 -# env: -# SLACK_WEBHOOK_URL: ${{ secrets.SPRING_RELEASE_SLACK_WEBHOOK_URL }} -# SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK -# with: -# payload: | -# { -# "text": "${{ github.event.repository.name }}-announcing `${{ env.MILESTONE }}`" -# } \ No newline at end of file + - name: Announce Release on Slack + uses: slackapi/slack-github-action@v1.24.0 + if: env.SLACK_WEBHOOK_URL + env: + SLACK_WEBHOOK_URL: ${{ secrets.SPRING_RELEASE_SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + with: + payload: | + { + "text": "${{ github.event.repository.name }}-announcing `${{ env.MILESTONE }}`" + } \ No newline at end of file diff --git a/.github/workflows/spring-stage-release.yml b/.github/workflows/spring-stage-release.yml index 213e643..005d684 100644 --- a/.github/workflows/spring-stage-release.yml +++ b/.github/workflows/spring-stage-release.yml @@ -55,7 +55,7 @@ jobs: staging-with-gradle: needs: maven-or-gradle - if: ${{ needs.maven-or-gradle.outputs.isMaven == 'false' }} + if: needs.maven-or-gradle.outputs.isMaven == 'false' uses: ./.github/workflows/spring-artifactory-gradle-release-staging.yml with: releaseVersion: ${{ inputs.releaseVersion }} @@ -65,7 +65,7 @@ jobs: staging-with-maven: needs: maven-or-gradle - if: ${{ needs.maven-or-gradle.outputs.isMaven == 'true' }} + if: needs.maven-or-gradle.outputs.isMaven == 'true' uses: ./.github/workflows/spring-artifactory-maven-release-staging.yml with: releaseVersion: ${{ inputs.releaseVersion }} diff --git a/README.md b/README.md index 0ef82a7..f7d9971 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ GPG_PRIVATE_KEY ``` The Gradle Enterprise secrets are optional: not used by Maven and Gradle project might not be enrolled for the service. +The `SPRING_RELEASE_SLACK_WEBHOOK_URL` secret is also optional: probably you don't want to notify Slack about your release. The mentioned secrets must be passed explicitly since these reusable workflows might be in different GitHub org than target project. @@ -71,7 +72,7 @@ This job stages released artifacts using JFrog CLI into `libs-staging-local` rep - When verification is successful, next job promotes release from staging either to `libs-milestone-local` or `libs-release-local`(and Maven Central) according to the releasing version schema - Then [spring-finalize-release.yml](.github/workflows/spring-finalize-release.yml) job is executed, which generates release notes using [Spring Changelog Generator](https://github.com/spring-io/github-changelog-generator) excluding repository admins from `Contributors` section. The `gh release create` command is performed on a tag for just released version. -And in the end the milestone is closed and specific Slack channel is notified about release. +And in the end the milestone is closed and specific Slack channel is notified about release (if `SPRING_RELEASE_SLACK_WEBHOOK_URL` secret is present in the repository). #### Example of Release caller workflow: https://github.com/artembilan/spring-messaging-build-tools/blob/decee2963c926c34f1f52bf373a3bc1dc09f1724/samples/release.yml#L1-L25 @@ -82,6 +83,15 @@ The `buildToolArgs` parameter for this job means extra build tool arguments. For example, the mentioned `dist` value is a Gradle task in the project. Can be any Maven goal or other command line arguments. +In the end you just need to go to the `Actions` tab on your project, press `Run workflow` on your release workflow and choose a branch from drop-down list to release currently scheduled Milestone against. +Such a release workflow can also be scheduled (`cron`, fo example) against branches matrix: + + +> **Warning** +> The [spring-artifactory-release.yml](.github/workflows/spring-artifactory-release.yml) already uses 3 of 4 levels of nested reusable workflows. +> Where the caller workflow is the last one. +> Therefore don't try to reuse your caller workflow. + ## Verify Staged Artifacts The `verify-staged` job expects an optional `verifyStagedWorkflow` input (the `verify-staged-artifacts.yml`, by default) workflow supplied from the target project. @@ -96,3 +106,5 @@ https://github.com/artembilan/spring-messaging-build-tools/blob/dbd138bf504abec5 Gradle projects must not manage `com.jfrog.artifactory` plugin anymore: the `jf gradlec` command sets up this plugin and respective tasks into a project using JFrog specific Gradle init script. In addition, the [spring-artifactory-gradle-snapshot.yml](.github/workflows/spring-artifactory-gradle-snapshot.yml) and [spring-artifactory-gradle-release-staging.yml](.github/workflows/spring-artifactory-gradle-release-staging.yml) add `spring-project-init.gradle` script to provide an `artifactory` plugin settings for artifacts publications. This script also adds a `nextDevelopmentVersion` task which is used when release has been staged and job is ready to push `Next development version` commit. + +See more information in the [Reusing Workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows). \ No newline at end of file diff --git a/samples/schedule-releases.yml b/samples/schedule-releases.yml new file mode 100644 index 0000000..03ff2f1 --- /dev/null +++ b/samples/schedule-releases.yml @@ -0,0 +1,19 @@ +name: Release Scheduler +on: + schedule: + - cron: '15 15 * * MON' # Every Monday at 3:15pm UTC + +jobs: + dispatch_scheduled_releases: + strategy: + matrix: + # List of active maintenance branches. + branch: [ main, 6.1.x, 6.0.x, 5.8.x ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Dispatch + env: + GITHUB_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} + run: gh workflow run release.yml -r ${{ matrix.branch }} \ No newline at end of file