From 5b4107cbad4c5cf830aa41b511ca00fd6cddacd7 Mon Sep 17 00:00:00 2001 From: Chris Bono Date: Sun, 16 Mar 2025 22:35:20 -0500 Subject: [PATCH] [CI] Fix GH token in release steps Also adds a temporary release-adhoc.yml worklfow to handle the last pieces of the release job that failed. --- .github/workflows/ci.yml | 2 + .github/workflows/release-adhoc.yml | 96 +++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 .github/workflows/release-adhoc.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c05eb0b6..db6b9563 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -189,6 +189,8 @@ jobs: git tag v$VERSION git push --tags origin - name: Changelog Config File + env: + GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} run: | repositoryTeam=$(gh api repos/$GITHUB_REPOSITORY/collaborators --jq 'map(select(.role_name == "admin") | .login) | tostring') repositoryTeam=$(sed 's/"//g' <<< ${repositoryTeam:1:-1}) diff --git a/.github/workflows/release-adhoc.yml b/.github/workflows/release-adhoc.yml new file mode 100644 index 00000000..2c5d3a92 --- /dev/null +++ b/.github/workflows/release-adhoc.yml @@ -0,0 +1,96 @@ +name: CI + +on: + workflow_dispatch: + inputs: + run-trivy-scan: + description: 'Run Trivy scan ?' + default: true + required: false + type: boolean + +env: + GCHAT_WEBHOOK_URL: ${{ secrets.SPRING_RELEASE_GCHAT_WEBHOOK_URL }} + DEVELOCITY_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_SECRET_ACCESS_KEY }} + COMMIT_OWNER: ${{ github.event.pusher.name }} + COMMIT_SHA: ${{ github.sha }} + ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }} + ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }} + +jobs: + prerequisites: + name: Pre-requisites for building + runs-on: ubuntu-latest + if: github.repository == 'spring-projects/spring-pulsar' + outputs: + runjobs: ${{ steps.continue.outputs.runjobs }} + project_version: ${{ steps.continue.outputs.project_version }} + boot_version: ${{ steps.continue.outputs.boot_version }} + steps: + - uses: actions/checkout@v4 + - id: continue + name: Determine if should continue + run: | + # Run jobs if in upstream repository + echo "runjobs=true" >>$GITHUB_OUTPUT + # Extract version from gradle.properties + version=$(cat gradle.properties | grep "version=" | awk -F'=' '{print $2}') + echo "project_version=$version" >>$GITHUB_OUTPUT + bootVersion=$(cat gradle/libs.versions.toml | grep "spring-boot = \"" | cut -d '"' -f2) + echo "boot_version=$bootVersion" >>$GITHUB_OUTPUT + + perform_release: + name: Perform Release + needs: [prerequisites] + runs-on: ubuntu-latest + permissions: + contents: write + timeout-minutes: 120 + if: ${{ !endsWith(needs.prerequisites.outputs.project_version, '-SNAPSHOT') }} + env: + REPO: ${{ github.repository }} + BRANCH: ${{ github.ref_name }} + VERSION: ${{ needs.prerequisites.outputs.project_version }} + steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} + - uses: spring-io/spring-gradle-build-action@v2 + - name: Changelog Config File + env: + GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} + run: | + repositoryTeam=$(gh api repos/$GITHUB_REPOSITORY/collaborators --jq 'map(select(.role_name == "admin") | .login) | tostring') + repositoryTeam=$(sed 's/"//g' <<< ${repositoryTeam:1:-1}) + repositoryVisibility=$(gh repo view --json visibility --jq .[]) + repositoryVisibility=$([[ $repositoryVisibility = 'PUBLIC' ]] && echo 'true' || echo 'false') + echo "changelog.contributors.exclude.names=$repositoryTeam" > changelog.properties + echo "changelog.issues.generate-links=$repositoryVisibility" >> changelog.properties + - name: Generate Changelog + uses: spring-io/github-changelog-generator@v0.0.11 + with: + milestone: ${{ env.VERSION }} + token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }} + config-file: changelog.properties + - name: GitHub Release + run: | + RELEASE_URL=$(gh release create v${{ env.VERSION }} -F changelog.md ${{ (contains(env.VERSION, '-M') || contains(env.VERSION, '-RC')) && '--prerelease' || '' }}) + echo "::notice title=Release Page::$RELEASE_URL" + - name: Close Milestone + run: | + MILESTONE_ID=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq '.[] | select(.title == "${{ env.VERSION }}") | .number') + if [ $MILESTONE_ID ]; then + gh api -X PATCH repos/$GITHUB_REPOSITORY/milestones/$MILESTONE_ID -f state='closed' --silent + fi + - name: Announce Release in Chat + if: env.GCHAT_WEBHOOK_URL + run: | + curl -X POST '${{ env.GCHAT_WEBHOOK_URL }}' \ + -H 'Content-Type: application/json' \ + -d '{ text: "${{ github.event.repository.name }}-announcing `${{ env.VERSION }}`"}' + - name: Update next snapshot version + run: | + echo "Updating $REPO@$VERSION to next snapshot version." + ./gradlew :updateToSnapshotVersion + git commit -am "[Release $VERSION] Next development version" + git push