|
| 1 | +name: CI (Release AdHoc) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | + - '1.2.x' |
| 8 | + paths-ignore: |
| 9 | + - '.github/**' |
| 10 | + schedule: |
| 11 | + - cron: '0 11 * * *' # Once per day at 11am UTC |
| 12 | + workflow_dispatch: |
| 13 | + inputs: |
| 14 | + run-trivy-scan: |
| 15 | + description: 'Run Trivy scan ?' |
| 16 | + default: true |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + |
| 20 | +env: |
| 21 | + GCHAT_WEBHOOK_URL: ${{ secrets.SPRING_RELEASE_GCHAT_WEBHOOK_URL }} |
| 22 | + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }} |
| 23 | + COMMIT_OWNER: ${{ github.event.pusher.name }} |
| 24 | + COMMIT_SHA: ${{ github.sha }} |
| 25 | + ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} |
| 26 | + ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} |
| 27 | + GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} |
| 28 | + |
| 29 | +jobs: |
| 30 | + prerequisites: |
| 31 | + name: Pre-requisites for building |
| 32 | + runs-on: ubuntu-latest |
| 33 | + if: github.repository == 'spring-projects/spring-pulsar' |
| 34 | + outputs: |
| 35 | + runjobs: ${{ steps.continue.outputs.runjobs }} |
| 36 | + project_version: ${{ steps.continue.outputs.project_version }} |
| 37 | + boot_version: ${{ steps.continue.outputs.boot_version }} |
| 38 | + should_deploy_artifacts: ${{ steps.should-deploy-artifacts.outputs.result }} |
| 39 | + steps: |
| 40 | + - uses: actions/checkout@v6 |
| 41 | + - id: continue |
| 42 | + name: Determine if should continue |
| 43 | + run: | |
| 44 | + # Run jobs if in upstream repository |
| 45 | + echo "runjobs=true" >>$GITHUB_OUTPUT |
| 46 | + # Extract version from gradle.properties |
| 47 | + version=$(cat gradle.properties | grep "version=" | awk -F'=' '{print $2}') |
| 48 | + echo "project_version=$version" >>$GITHUB_OUTPUT |
| 49 | + bootVersion=$(cat gradle/libs.versions.toml | grep "spring-boot = \"" | cut -d '"' -f2) |
| 50 | + echo "boot_version=$bootVersion" >>$GITHUB_OUTPUT |
| 51 | + - id: should-deploy-artifacts |
| 52 | + name: Check Deploy Artifacts using Secrets |
| 53 | + if: ${{ runner.os == 'Linux' }} |
| 54 | + run: | |
| 55 | + if [[ -z "$ARTIFACTORY_PASSWORD" ]] ; then |
| 56 | + echo "result=false" >> $GITHUB_OUTPUT |
| 57 | + else |
| 58 | + echo "result=true" >> $GITHUB_OUTPUT |
| 59 | + fi |
| 60 | + perform_release: |
| 61 | + name: Perform Release |
| 62 | + needs: [prerequisites] |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: write |
| 66 | + timeout-minutes: 120 |
| 67 | + if: ${{ !endsWith(needs.prerequisites.outputs.project_version, '-SNAPSHOT') }} |
| 68 | + env: |
| 69 | + REPO: ${{ github.repository }} |
| 70 | + BRANCH: ${{ github.ref_name }} |
| 71 | + VERSION: ${{ needs.prerequisites.outputs.project_version }} |
| 72 | + TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} |
| 73 | + MILESTONE_REPO: https://repo1.maven.org/maven2 |
| 74 | + RELEASE_REPO: https://repo1.maven.org/maven2 |
| 75 | + ARTIFACT_PATH: org/springframework/pulsar/spring-pulsar |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v6 |
| 78 | + with: |
| 79 | + token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} |
| 80 | + - uses: spring-io/spring-gradle-build-action@v2 |
| 81 | + with: |
| 82 | + java-version: '25' |
| 83 | + distribution: 'liberica' |
| 84 | + - name: Wait for Milestone Artifacts |
| 85 | + if: ${{ contains(needs.prerequisites.outputs.project_version, '-RC') || contains(needs.prerequisites.outputs.project_version, '-M') }} |
| 86 | + env: |
| 87 | + VERSION: ${{ needs.prerequisites.outputs.project_version }} |
| 88 | + run: | |
| 89 | + echo "Wait for artifacts of $REPO@$VERSION to appear on milestone repository ($MILESTONE_REPO)." |
| 90 | + until curl -f -s $MILESTONE_REPO/$ARTIFACT_PATH/$VERSION/ > /dev/null |
| 91 | + do |
| 92 | + sleep 30 |
| 93 | + echo "." |
| 94 | + done |
| 95 | + echo "Artifacts for $REPO@$VERSION have been released to milestone repository ($MILESTONE_REPO)." |
| 96 | + - name: Wait for Release Artifacts |
| 97 | + if: ${{ !contains(needs.prerequisites.outputs.project_version.version, '-RC') && !contains(needs.prerequisites.outputs.project_version, '-M') }} |
| 98 | + env: |
| 99 | + VERSION: ${{ needs.prerequisites.outputs.project_version }} |
| 100 | + run: | |
| 101 | + echo "Wait for artifacts of $REPO@$VERSION to appear on release repository ($RELEASE_REPO)." |
| 102 | + until curl -f -s $RELEASE_REPO/$ARTIFACT_PATH/$VERSION/ > /dev/null |
| 103 | + do |
| 104 | + sleep 30 |
| 105 | + echo "." |
| 106 | + done |
| 107 | + echo "Artifacts for $REPO@$VERSION have been released to release repository ($RELEASE_REPO)." |
| 108 | + - name: Setup git for release tagging |
| 109 | + run: | |
| 110 | + git config user.name 'github-actions[bot]' |
| 111 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 112 | + - name: Tag release |
| 113 | + run: | |
| 114 | + echo "Tagging $REPO@$VERSION release." |
| 115 | + git tag v$VERSION |
| 116 | + git push --tags origin |
| 117 | + - name: Changelog Config File |
| 118 | + run: | |
| 119 | + repositoryTeam=$(gh api repos/$GITHUB_REPOSITORY/collaborators --jq 'map(select(.role_name == "admin") | .login) | tostring') |
| 120 | + repositoryTeam=$(sed 's/"//g' <<< ${repositoryTeam:1:-1}) |
| 121 | + repositoryVisibility=$(gh repo view --json visibility --jq .[]) |
| 122 | + repositoryVisibility=$([[ $repositoryVisibility = 'PUBLIC' ]] && echo 'true' || echo 'false') |
| 123 | + echo "changelog.contributors.exclude.names=$repositoryTeam" > changelog.properties |
| 124 | + echo "changelog.issues.generate-links=$repositoryVisibility" >> changelog.properties |
| 125 | + - name: Generate Changelog |
| 126 | + |
| 127 | + with: |
| 128 | + milestone: ${{ env.VERSION }} |
| 129 | + token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} |
| 130 | + config-file: changelog.properties |
| 131 | + - name: GitHub Release |
| 132 | + run: | |
| 133 | + RELEASE_URL=$(gh release create v${{ env.VERSION }} -F changelog.md ${{ (contains(env.VERSION, '-M') || contains(env.VERSION, '-RC')) && '--prerelease' || '' }}) |
| 134 | + echo "::notice title=Release Page::$RELEASE_URL" |
| 135 | + - name: Close Milestone |
| 136 | + run: | |
| 137 | + MILESTONE_ID=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq '.[] | select(.title == "${{ env.VERSION }}") | .number') |
| 138 | + if [ $MILESTONE_ID ]; then |
| 139 | + gh api -X PATCH repos/$GITHUB_REPOSITORY/milestones/$MILESTONE_ID -f state='closed' --silent |
| 140 | + fi |
| 141 | + - name: Announce Release in Chat |
| 142 | + if: env.GCHAT_WEBHOOK_URL |
| 143 | + run: | |
| 144 | + curl -X POST '${{ env.GCHAT_WEBHOOK_URL }}' \ |
| 145 | + -H 'Content-Type: application/json' \ |
| 146 | + -d '{ text: "${{ github.event.repository.name }}-announcing `${{ env.VERSION }}`"}' |
| 147 | + - name: Update next snapshot version |
| 148 | + run: | |
| 149 | + echo "Updating $REPO@$VERSION to next snapshot version." |
| 150 | + ./gradlew :updateToSnapshotVersion |
| 151 | + git commit -am "[Release $VERSION] Next development version" |
| 152 | + git push |
0 commit comments