Skip to content

Commit

Permalink
Make Slack notification step optional
Browse files Browse the repository at this point in the history
* Simply some `if:` expressions
* Document how to run release workflow
* Add `on: schedule:` example
* Add warning into docs about nested reusable workflow levels
  • Loading branch information
artembilan committed Nov 17, 2023
1 parent b97ad92 commit 3231d7b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/spring-artifactory-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
23 changes: 12 additions & 11 deletions .github/workflows/spring-finalize-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

secrets:
SPRING_RELEASE_SLACK_WEBHOOK_URL:
required: true
required: false
GH_ACTIONS_REPO_TOKEN:
required: true

Expand Down Expand Up @@ -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/[email protected]
# 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 }}`"
# }
- name: Announce Release on Slack
uses: slackapi/[email protected]
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 }}`"
}
4 changes: 2 additions & 2 deletions .github/workflows/spring-stage-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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).
19 changes: 19 additions & 0 deletions samples/schedule-releases.yml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 3231d7b

Please sign in to comment.