Refactor workflows to avoid > 3 nested levels

This commit is contained in:
Artem Bilan
2023-11-16 09:23:02 -05:00
parent 59c1400213
commit 0df7d540f7
7 changed files with 59 additions and 84 deletions

View File

@@ -7,8 +7,7 @@ run-name: Release current version for branch ${{ github.ref_name }}
jobs:
release:
uses: spring-projects/spring-integration-aws/.github/workflows/spring-release-for-branch.yml@main
uses: spring-projects/spring-integration-aws/.github/workflows/spring-artifactory-release.yml@main
with:
buildToolArgs: dist
repositoryTeam: artembilan,garyrussell
secrets: inherit

View File

@@ -70,8 +70,6 @@ jobs:
echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
echo buildName=$buildName >> $GITHUB_OUTPUT
echo buildNumber=$JFROG_CLI_BUILD_NUMBER >> $GITHUB_OUTPUT
echo "::notice ::Artifactory Build Name=$JFROG_CLI_BUILD_NAME"
echo "::notice ::Artifactory Build Number=$JFROG_CLI_BUILD_NUMBER"
- name: Set Release Version
run: sed -i "s/version=.*/version=${{ inputs.releaseVersion }}/" gradle.properties

View File

@@ -61,8 +61,6 @@ jobs:
echo JFROG_CLI_BUILD_NUMBER=$GITHUB_RUN_NUMBER >> $GITHUB_ENV
echo buildName=$buildName >> $GITHUB_OUTPUT
echo buildNumber=$JFROG_CLI_BUILD_NUMBER >> $GITHUB_OUTPUT
echo "::notice ::Artifactory Build Name=$JFROG_CLI_BUILD_NAME"
echo "::notice ::Artifactory Build Number=$JFROG_CLI_BUILD_NUMBER"
- name: Set Release Version
run: |

View File

@@ -11,24 +11,50 @@ on:
description: 'Additional Maven or Gradle command arguments: tasks, goals, plugins etc. The `install` for Maven is included. The `build` and `artifactoryPublish` for Gradle are included.'
required: false
type: string
repositoryTeam:
description: 'Comma-separate GitHub user names for repository team members to exclude from contributors'
required: false
type: string
jobs:
releaseVersion:
runs-on: ubuntu-latest
outputs:
releaseVersion: ${{ steps.release-version.outputs.releaseVersion }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- name: Find Current Version to Release
id: release-version
run: |
if test -f pom.xml
then
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression="project.version" -q -DforceStdout)
else
CURRENT_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}')
fi
export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
RELEASE_VERSION=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.title | startswith(env.CANDIDATE_VERSION))) | .[0] | .title')
if [ -z $RELEASE_VERSION ]; then
echo "::error::No scheduled milestone for $CURRENT_VERSION version."
exit 1
fi
echo releaseVersion=$RELEASE_VERSION >> $GITHUB_OUTPUT
echo "::notice::RELEASE VERSION=$RELEASE_VERSION"
staging:
needs: releaseVersion
uses: spring-projects/spring-integration-aws/.github/workflows/spring-stage-release.yml@main
with:
releaseVersion: ${{ inputs.releaseVersion }}
releaseVersion: ${{ needs.releaseVersion.outputs.releaseVersion }}
buildToolArgs: ${{ inputs.buildToolArgs }}
secrets: inherit
verify-staged:
needs: staging
needs: [releaseVersion, staging]
uses: ./.github/workflows/verify-staged-artifacts.yml
with:
releaseVersion: ${{ inputs.releaseVersion }}
releaseVersion: ${{ needs.releaseVersion.outputs.releaseVersion }}
secrets: inherit
promote-milestone:
@@ -51,9 +77,8 @@ jobs:
finalize:
if: ${{ !(failure() || cancelled()) }}
needs: [promote-milestone, promote-ga]
needs: [releaseVersion, promote-milestone, promote-ga]
uses: spring-projects/spring-integration-aws/.github/workflows/spring-finalize-release.yml@main
with:
milestone: ${{ inputs.releaseVersion }}
repositoryTeam: ${{ inputs.repositoryTeam }}
milestone: ${{ needs.releaseVersion.outputs.releaseVersion }}
secrets: inherit

View File

@@ -7,10 +7,6 @@ on:
description: 'Milestone title, e.g 3.0.0-M1, 3.1.0-RC1, 3.2.0 etc.'
required: true
type: string
repositoryTeam:
description: 'Comma-separate GitHub user names for repository team members to exclude from contributors'
required: false
type: string
env:
MILESTONE: ${{ inputs.milestone }}
@@ -27,13 +23,16 @@ jobs:
- name: Generate Changelog
run: |
repositoryTeam=$(gh api repos/$GITHUB_REPOSITORY/collaborators --jq 'map(select(.role_name == "admin") | .login) | tostring')
repositoryTeam=$(sed 's/"//g' <<< ${repositoryTeam:1:-1})
wget -q https://github.com/spring-io/github-changelog-generator/releases/download/v0.0.8/github-changelog-generator.jar
java -jar github-changelog-generator.jar $MILESTONE changelog.md \
--changelog.repository=$GITHUB_REPOSITORY \
--github.username=spring-builds \
--github.password=$GITHUB_TOKEN \
--changelog.contributors.exclude.names=${{ inputs.repositoryTeam }}
--changelog.contributors.exclude.names=$repositoryTeam
- name: GitHub Release
run: gh release create v${{ env.MILESTONE }} -F changelog.md ${{ (contains(env.MILESTONE, '-M') || contains(env.MILESTONE, '-RC')) && '--prerelease' }}
@@ -45,13 +44,13 @@ 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 }}`"
}
# - 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 }}`"
# }

View File

@@ -1,48 +0,0 @@
name: Perform Release with Artifactory
on:
workflow_call:
inputs:
buildToolArgs:
description: 'Additional Maven or Gradle command arguments: tasks, goals, plugins etc. The `install` for Maven is included. The `build` and `artifactoryPublish` for Gradle are included.'
required: false
type: string
repositoryTeam:
description: 'Comma-separate GitHub user names for repository team members to exclude from contributors'
required: false
type: string
jobs:
releaseVersion:
runs-on: ubuntu-latest
outputs:
releaseVersion: ${{ steps.release-version.outputs.releaseVersion }}
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- name: Find Current Version to Release
id: release-version
run: |
if test -f pom.xml
then
CURRENT_VERSION=$(./mvnw help:evaluate -Dexpression="project.version" -q -DforceStdout)
else
CURRENT_VERSION=$(./gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}')
fi
export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
RELEASE_VERSION=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.title | startswith(env.CANDIDATE_VERSION))) | .[0] | .title')
echo releaseVersion=$RELEASE_VERSION >> $GITHUB_OUTPUT
echo "::notice ::RELEASE VERSION=$RELEASE_VERSION"
perform-release:
needs: releaseVersion
uses: spring-projects/spring-integration-aws/.github/workflows/spring-artifactory-release.yml@main
with:
releaseVersion: ${{ needs.releaseVersion.outputs.releaseVersion }}
buildToolArgs: ${{ inputs.buildToolArgs }}
repositoryTeam: ${{ inputs.repositoryTeam }}
secrets: inherit

View File

@@ -75,9 +75,13 @@ jobs:
run: |
if [ ${{ needs.staging-with-gradle.outputs.buildName }} ]
then
echo buildName=${{ needs.staging-with-gradle.outputs.buildName }} >> $GITHUB_OUTPUT
echo buildNumber=${{ needs.staging-with-gradle.outputs.buildNumber }} >> $GITHUB_OUTPUT
buildName=${{ needs.staging-with-gradle.outputs.buildName }}
buildNumber=${{ needs.staging-with-gradle.outputs.buildNumber }}
else
echo buildName=${{ needs.staging-with-maven.outputs.buildName }} >> $GITHUB_OUTPUT
echo buildNumber=${{ needs.staging-with-maven.outputs.buildNumber }} >> $GITHUB_OUTPUT
fi
buildName=${{ needs.staging-with-maven.outputs.buildName }}
buildNumber=${{ needs.staging-with-maven.outputs.buildNumber }}
fi
echo buildName=$buildName >> $GITHUB_OUTPUT
echo buildNumber=$buildNumber >> $GITHUB_OUTPUT
echo "::notice::Artifactory Build Name=$buildName"
echo "::notice::Artifactory Build Number=$buildNumber"