-
Notifications
You must be signed in to change notification settings - Fork 14
Github Action - Create Release and Deploy #312
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,134 @@ | ||
| # | ||
| # Copyright 2018 ABSA Group Limited | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Create a new release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| release-version: | ||
| description: "Define the release version (e.g., v4.7.0)" | ||
| required: true | ||
| default: "" | ||
| development-version: | ||
| description: "Define the snapshot version (e.g., v4.7.1)" | ||
| required: true | ||
| default: "" | ||
|
|
||
| jobs: | ||
| create-release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 # Fetch all history for all tags and branches | ||
|
|
||
| - name: Validate format of received tag | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const releaseVersion = core.getInput('release-version'); | ||
| const developmentVersion = core.getInput('development-version'); | ||
| const regex = /^v[0-9]+\.[0-9]+\.[0-9]+$/; | ||
| if (!regex.test(releaseVersion)) { | ||
| core.setFailed('Release version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2'); | ||
| return; | ||
| } | ||
| if (!regex.test(developmentVersion)) { | ||
| core.setFailed('Development version does not match the required format "v[0-9]+.[0-9]+.[0-9]+". Valid example: v0.5.2'); | ||
| return; | ||
| } | ||
| release-version: ${{ github.event.inputs.release-version }} | ||
| development-version: ${{ github.event.inputs.development-version }} | ||
|
|
||
| - name: Define semantic version number | ||
| id: semantic_version | ||
| run: | | ||
| RELEASE_VERSION="${{ github.event.inputs.release-version }}" | ||
| RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION#v} | ||
|
|
||
| DEVELOPMENT_VERSION="${{ github.event.inputs.development-version }}" | ||
| DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION#v} | ||
|
|
||
| echo "RELEASE_VERSION_WITHOUT_V=${RELEASE_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}" | ||
| echo "DEVELOPMENT_VERSION_WITHOUT_V=${DEVELOPMENT_VERSION_WITHOUT_V}" >> "${GITHUB_ENV}" | ||
| - name: Configure Git | ||
| run: | | ||
| git config --global user.name "${{ github.actor }}" | ||
| git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
| - name: Create release branch | ||
| run: | | ||
| git checkout -b release/${RELEASE_VERSION_WITHOUT_V} | ||
| git push origin release/${RELEASE_VERSION_WITHOUT_V} | ||
| - name: Set up JDK 1.8 | ||
| uses: actions/setup-java@v1 | ||
| with: | ||
| java-version: '1.8' | ||
|
|
||
| - name: Set Maven project version, create tag | ||
| run: | | ||
| git pull origin release/${RELEASE_VERSION_WITHOUT_V} | ||
| mvn versions:set -DnewVersion=${RELEASE_VERSION_WITHOUT_V} --no-transfer-progress | ||
| mvn versions:commit | ||
| git commit -am "Set project version to ${RELEASE_VERSION_WITHOUT_V}" | ||
| git push origin release/${RELEASE_VERSION_WITHOUT_V} | ||
| - name: Create tag | ||
| run: | | ||
| git tag ${{ github.event.inputs.release-version }} | ||
| git push origin ${{ github.event.inputs.release-version }} | ||
| - name: Set next development version | ||
| run: | | ||
| # Assumes semantic versioning and increments the minor version. Adjust the awk command as needed for different versioning schemes. | ||
| NEXT_VERSION=$(echo ${DEVELOPMENT_VERSION_WITHOUT_V} | awk -F. '{print $1"."$2"."$3"-SNAPSHOT"}') | ||
| mvn versions:set -DnewVersion=$NEXT_VERSION --no-transfer-progress | ||
| mvn versions:commit | ||
| git commit -am "Set project version to $NEXT_VERSION" | ||
| git push origin release/${RELEASE_VERSION_WITHOUT_V} | ||
| - name: Get Default Branch | ||
| id: get_default_branch | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const response = await github.rest.repos.get({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo | ||
| }); | ||
| return response.data.default_branch; | ||
| - name: Create Pull Request | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| script: | | ||
| const branch = `release/${process.env.RELEASE_VERSION_WITHOUT_V}`; | ||
| await github.rest.pulls.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title: 'Release ${{ github.event.inputs.release-version }}', | ||
| head: branch, | ||
| base: ${{ steps.get_default_branch.outputs.result }}, | ||
| body: 'Pull request to merge release ${{ github.event.inputs.release-version }} into default branch', | ||
| draft: false | ||
| }); | ||
| - name: Create Draft Release | ||
| uses: softprops/action-gh-release@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| name: ${{ github.event.inputs.release-version }} | ||
| body: ${{ steps.generate_release_notes.outputs.releaseNotes }} | ||
| tag_name: ${{ github.event.inputs.release-version }} | ||
| draft: true | ||
| prerelease: false | ||
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,65 @@ | ||
| # | ||
| # Copyright 2018 ABSA Group Limited | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
|
|
||
| name: Deploy | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| deploy: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| scala: [ 2.11, 2.12 ] | ||
| spark: [ 2, 3 ] | ||
| exclude: | ||
| - scala: 2.11 | ||
| spark: 3 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-tags: true | ||
| fetch-depth: 0 # Fetch all history for all tags and branches | ||
|
|
||
| - name: Set up JDK 1.8 | ||
| uses: actions/setup-java@v1 | ||
| with: | ||
| java-version: '1.8' | ||
|
|
||
| - name: Import GPG keys | ||
| run: | | ||
| echo "${{ secrets.MAVEN_GPG_PRIVATE_KEY }}" | base64 --decode | gpg --batch --import --keyserver https://keyserver.ubuntu.com/ | ||
| echo "${{ secrets.MAVEN_GPG_PASSPHRASE }}" | gpg --passphrase-fd 0 --batch --pinentry-mode loopback --import-ownertrust <<< . | ||
| - name: Create settings.xml | ||
| run: | | ||
| echo "<settings xmlns=\"http://maven.apache.org/SETTINGS/1.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd\"> | ||
| <servers> | ||
| <server> | ||
| <id>ossrh</id> | ||
| <username>${{ secrets.OSSRH_USERNAME }}</username> | ||
| <password>${{ secrets.OSSRH_TOKEN }}</password> | ||
| </server> | ||
| </servers> | ||
| </settings>" > $HOME/.m2/settings.xml | ||
| - name: Build and deploy artifact | ||
| env: | ||
| MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | ||
| MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | ||
| run: | | ||
| mvn scala-cross-build:change-version -Pscala-${{ matrix.scala }},spark-${{ matrix.spark }} | ||
| mvn -B -e -DskipTests -Dmanual-release -Pdeploy,scala-${{ matrix.scala }},spark-${{ matrix.spark }} -Dossrh clean deploy -Dossrh.username=${{ secrets.OSSRH_USERNAME }} -Dossrh.password=${{ secrets.OSSRH_TOKEN }} -Dgpg.passphrase=${{ secrets.MAVEN_GPG_PASSPHRASE }} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use this to determine the next development version from the release version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like current version, you set what is the release version and what is the development version. Above assumes that we always increment the same digit all the time. But I will remove comment because that is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not going to argue about such a thing, but in that case you need to make sure that the development version will end with
-SNAPSHOTThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appends it there
NEXT_VERSION=$(echo ${DEVELOPMENT_VERSION_WITHOUT_V} | awk -F. '{print $1"."$2"."$3"-SNAPSHOT"}')