-
Notifications
You must be signed in to change notification settings - Fork 10
ci: implement automated releasing #446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karel-rehor
wants to merge
18
commits into
main
Choose a base branch
from
ci/stage-automated-releasing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6f7e549
ci: github action for automated releasing to stage (#445)
karel-rehor 6b070df
chore: replace ossrh references with maven central.
karel-rehor 6f4b4df
chore: prioritize pom version checks in on-release.sh
karel-rehor 471133f
chore: add CRLF to error message.
karel-rehor 4f67eac
Merge branch 'main' into ci/stage-automated-releasing
karel-rehor 6676686
docs: fix PR number in CHANGELOG.md
karel-rehor efb0d75
docs: fix phantom space in CHANGELOG.md
karel-rehor 7c64374
chore: workflow security fixes
karel-rehor 7b42611
chore: start scm-settings.xml
karel-rehor 1577811
chore: protect gpg-passphrase in workflow.
karel-rehor aada4b6
chore: add license to scm-settings.xml
karel-rehor 54563a8
chore: switch repository secrets to environment secrets.
karel-rehor 9c05e23
chore: remove tag filter for release event - not applicable to 'relea…
karel-rehor 47afe9b
chore: revert workflow env back to secrets
karel-rehor 994733a
chore: match envirionment in workflow to gerun releasing
karel-rehor a910045
build(deps): bump com.google.protobuf:protobuf-java (#447)
dependabot[bot] 698050d
build(deps): bump github/codeql-action from 4.38.0 to 4.38.1 (#448)
dependabot[bot] 33cfd77
Merge branch 'main' into ci/stage-automated-releasing
karel-rehor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,241 @@ | ||
| name: Maven Releasing | ||
|
|
||
| on: | ||
|
|
||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| release: | ||
| permissions: | ||
| contents: write # may want to update version | ||
| runs-on: ubuntu-latest | ||
| environment: releasing | ||
| env: | ||
| MAVEN_SETTINGS_EXPERIM: ${{ vars.MAVEN_SETTINGS_FILE }} | ||
| RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} | ||
| IS_PRERELEASE: ${{ github.event.release.prerelease }} | ||
| GITHUB_REPO: ${{ github.repository }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Setup JDK 21 | ||
| uses: actions/setup-java@v5 | ||
| with: | ||
| java-version: '21' | ||
| distribution: 'temurin' | ||
| cache: maven | ||
| gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | ||
| - name: Add dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get -y install libxml2-utils | ||
| - name: Verify Env | ||
| env: | ||
| GPG_PASSPHRASE_PRELIM: ${{ secrets.GPG_PASSPHRASE }} | ||
| SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | ||
| SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
| run: | | ||
| if [[ -z "${{ secrets.GPG_PRIVATE_KEY }}" ]] | ||
| then | ||
| echo "ERROR GPG_PRIVATE_KEY is missing." | ||
| exit 1 | ||
| fi | ||
| # ensure scm properties match current project - don't want to modify other repository inadvertently | ||
| POM_SITE_URL=$(xmllint --xpath "//*[local-name()='distributionManagement']/*[local-name()='site']/*[local-name()='url']/text()" ./pom.xml) | ||
| POM_SCM_CONNECTION=$(xmllint --xpath "//*[local-name()='scm']/*[local-name()='connection']/text()" ./pom.xml) | ||
| POM_SCM_DEVELOPER_CONNECTION=$(xmllint --xpath "//*[local-name()='scm']/*[local-name()='developerConnection']/text()" ./pom.xml) | ||
|
|
||
| if [[ "${POM_SITE_URL}" != "scm:git:https://github.com/${GITHUB_REPOSITORY}" ]] | ||
| then | ||
| echo "POM_SITE_URL ${POM_SITE_URL} does not match GITHUB_REPOSITORY ${GITHUB_REPOSITORY}" | ||
| exit 1 | ||
| else | ||
| echo "POM_SITE_URL OK ✓." | ||
| fi | ||
|
|
||
| if [[ ! "${POM_SCM_CONNECTION}" =~ .*${GITHUB_REPOSITORY}\.git$ ]] | ||
| then | ||
| echo "POM_SCM_CONNECTION ${POM_SCM_CONNECTION} does not match GITHUB_REPOSITORY ${GITHUB_REPOSITORY}" | ||
| exit 1 | ||
| else | ||
| echo "POM_SCM_CONNECTION OK ✓." | ||
| fi | ||
|
|
||
| if [[ ! "${POM_SCM_DEVELOPER_CONNECTION}" =~ .*${GITHUB_REPOSITORY}\.git$ ]] | ||
| then | ||
| echo "POM_SCM_DEVELOPER_CONNECTION ${POM_SCM_DEVELOPER_CONNECTION} does not match GITHUB_REPOSITORY ${GITHUB_REPOSITORY}" | ||
| exit 1 | ||
| else | ||
| echo "POM_SCM_DEVELOPER_CONNECTION OK ✓." | ||
| fi | ||
|
|
||
| if [[ -n "$SONATYPE_USERNAME" ]] | ||
| then | ||
| echo "have SONATYPE_USERNAME" | ||
| else | ||
| echo "Release requires SONATYPE_USERNAME, which was not found. exiting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -n "$SONATYPE_PASSWORD" ]] | ||
| then | ||
| echo "have SONATYPE_PASSWORD" | ||
| else | ||
| echo "Release requires SONATYPE_PASSWORD, which was not found. exiting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -n "$GPG_PASSPHRASE_PRELIM" ]] | ||
| then | ||
| echo "have GPG_PASSPHRASE_PRELIM" | ||
| else | ||
| echo "Release requires GPG_PASSPHRASE, which was not found. exiting" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Verify GPG2 environment | ||
| if ! command -v gpg2 &> /dev/null | ||
| then | ||
| echo "Failed to locate gpg2 on this host. GPG2 is required to continue." | ||
| exit 1 | ||
| fi | ||
|
|
||
| gpg2 --version | ||
| GPG_EXECUTABLE=$(command -v gpg2) | ||
| export GPG_EXECUTABLE | ||
| echo "GPG_EXECUTABLE=${GPG_EXECUTABLE}" >> "$GITHUB_ENV" | ||
|
|
||
| # Verify tag and next version | ||
| if ! echo "${RELEASE_TAG_NAME}" | grep -Ei '^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|beta)[0-9]*)?$' | ||
| then | ||
| echo "RELEASE_TAG_NAME ${RELEASE_TAG_NAME} does not match expected pattern, e.g. (v1.9.0). Exiting." | ||
| exit 1 | ||
| fi | ||
| VERSION_CLEAN="${RELEASE_TAG_NAME:1}" | ||
| # shellcheck disable=SC2206 | ||
| PARTS=(${VERSION_CLEAN//./ }) | ||
| # TODO Check if PARTS[2] starts with 0 or [1-9] if not 0 then this is hot release and should not trigger publishing | ||
| if ! echo "${PARTS[2]}" | grep -q "^0.*" | ||
| then | ||
| echo "Detected hot fix release ${RELEASE_TAG_NAME}" | ||
| echo "IS_HOT_FIX=true" >> "${GITHUB_ENV}" | ||
| fi | ||
| NEW_MINOR=$((PARTS[1]+1)) | ||
| NEXT_RELEASE="${PARTS[0]}.${NEW_MINOR}.0" | ||
| echo "NEXT_RELEASE=${NEXT_RELEASE}" >> "${GITHUB_ENV}" | ||
| NEXT_RELEASE_BRANCH="ci/next-cycle-${NEXT_RELEASE}" | ||
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
| git config user.name "${GITHUB_ACTOR}" | ||
|
|
||
| if [[ "${IS_PRERELEASE}" != "true" && "${RELEASE_TAG_NAME,,}" =~ ^v[0-9]+\.[0-9]+\.0$ ]] | ||
| then | ||
| BRANCH_CHECK=$(git ls-remote --heads origin "refs/heads/${NEXT_RELEASE_BRANCH}") | ||
| if [ -n "${BRANCH_CHECK}" ] | ||
| then | ||
| echo "branch ${NEXT_RELEASE_BRANCH} already exists in project. Cannot recreate it automatically." | ||
| echo "If you wish to use this automatically created branch, please delete the existing branch and start the release again" | ||
| exit 1 | ||
| fi | ||
| else | ||
| echo "Skipping next release cycle branch check because this is either a pre-release or a patch fix." | ||
| fi | ||
|
|
||
| echo "NEXT_RELEASE_BRANCH=${NEXT_RELEASE_BRANCH}" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Script | ||
| run: | | ||
| . ./scripts/on-release.sh | ||
| echo "RC_OR_BETA=${RC_OR_BETA}" >> "$GITHUB_ENV" | ||
| - name: Release | ||
| env: | ||
| GPG_PASSPHRASE_PRELIM: ${{ secrets.GPG_PASSPHRASE }} | ||
| SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} | ||
| SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} | ||
| run: | | ||
| if [[ "${IS_PRERELEASE}" == "true" ]]; then | ||
| echo "This is a pre release and will not be deployed to Maven Central." | ||
| exit 0 | ||
| fi | ||
| if [[ "${RC_OR_BETA}" == "true" ]] | ||
| then | ||
| echo "This is an RC or BETA release and will not be deployed to Maven Central." | ||
| exit 0 | ||
| fi | ||
| if [[ "$GPG_PASSPHRASE_PRELIM" == "EMPTY" ]]; then | ||
| echo "GPG_PASSPHRASE empty requested" | ||
| GPG_PASSPHRASE="" | ||
| else | ||
| GPG_PASSPHRASE="$GPG_PASSPHRASE_PRELIM" | ||
| fi | ||
| export GPG_PASSPHRASE | ||
| cat << EOF > release.properties | ||
| scm.url=scm\:git\:https\://github.com/${GITHUB_REPOSITORY}.git | ||
| scm.tag=${RELEASE_TAG_NAME} | ||
| EOF | ||
| cat release.properties | ||
| mvn release:perform \ | ||
| -Dgoals=deploy \ | ||
| -s ./deploy-settings.xml \ | ||
| -Darguments="-DskipTests -DskipITs -DperformRelease=true" | ||
| - name: Prepare next cycle | ||
| run: | | ||
| if [[ "${IS_PRERELEASE}" == "true" ]]; then | ||
| echo "This is a prerelease so the next release cycle will not be prepared." | ||
| exit 0 | ||
| fi | ||
| if [[ "${RC_OR_BETA}" == "true" ]] | ||
| then | ||
| echo "This is an RC or BETA release so next release cycle will not be prepared." | ||
| exit 0 | ||
| fi | ||
| if [[ "${IS_HOT_FIX}" == "true" ]] | ||
| then | ||
| echo "This is a hot fix release ${RELEASE_TAG_NAME}, so next release cycle will not be prepared." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Preparing next release cycle" | ||
|
|
||
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
| git config user.name "${GITHUB_ACTOR}" | ||
| echo "checking out next release branch ${NEXT_RELEASE_BRANCH}" | ||
| git checkout -b "${NEXT_RELEASE_BRANCH}" | ||
| mvn versions:set-scm-tag -DnewTag="HEAD" | ||
| mvn versions:set -DnextSnapshot=true -DnextSnapshotIndexToIncrement=1 | ||
| sed -i "1s/^/## ${NEXT_RELEASE} [unreleased]\n\n/" CHANGELOG.md | ||
| sed -i -e "s/<version>${RELEASE_TAG_NAME:1}<\/version>/<version>${NEXT_RELEASE}-SNAPSHOT<\/version>/" examples/pom.xml | ||
| git add pom.xml examples/pom.xml CHANGELOG.md | ||
| git commit -m "ci: setting up release cycle ${NEXT_RELEASE}" | ||
| git push --set-upstream origin "${NEXT_RELEASE_BRANCH}" | ||
| # The following requires special permissions on the organizational and project level to work. Switching off for now. | ||
| # gh pr create -B main -H ${NEXT_RELEASE_BRANCH} --title "Merge ${NEXT_RELEASE_BRANCH} into main" --body 'Created by GitHub action' | ||
| # The alternative is to create the PR by hand | ||
| echo "The branch ${NEXT_RELEASE_BRANCH} has been created. You can create and merge a PR manually from it to start the next release cycle." | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| - name: Publish documentation | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| if [[ "${IS_PRERELEASE}" == "true" ]]; then | ||
| echo "This is a pre release, so site documentation will not be updated to GitHub pages." | ||
| exit 0 | ||
| fi | ||
| if [[ "${RC_OR_BETA}" == "true" ]] | ||
| then | ||
| echo "This is an RC or BETA release, so site documentation will not be updated to GitHub pages." | ||
| exit 0 | ||
| fi | ||
| if [[ "${IS_HOT_FIX}" == "true" ]] | ||
| then | ||
| echo "This is a hot fix release ${RELEASE_TAG_NAME}, so site documentation will not be updated to GitHub pages." | ||
| exit 0 | ||
| fi | ||
| git config --global user.email "${GITHUB_ACTOR}@noreply.github.com" | ||
| git config --global user.name "GitHub Action" | ||
| git checkout "${RELEASE_TAG_NAME}" | ||
| mvn clean site site:stage -DskipTests | ||
| mvn -s scm-settings.xml --batch-mode scm-publish:publish-scm -Dscmpublish.serverId=github | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.