|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + releaseVersion: |
| 7 | + description: 'Release version if different than actual without SNAPSHOT' |
| 8 | + default: '' |
| 9 | + |
| 10 | +jobs: |
| 11 | + release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@v2 |
| 17 | + |
| 18 | + - name: Set up Java |
| 19 | + uses: actions/setup-java@v1 |
| 20 | + with: |
| 21 | + java-version: 11 |
| 22 | + |
| 23 | + - name: Cache |
| 24 | + uses: actions/cache@v2 |
| 25 | + with: |
| 26 | + path: ~/.m2/repository |
| 27 | + key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }} |
| 28 | + restore-keys: | |
| 29 | + ${{ runner.os }}-maven- |
| 30 | +
|
| 31 | + - name: Set up Git |
| 32 | + run: | |
| 33 | + git config --global user.name "jsonschema2pojo-androidx-databinding" |
| 34 | + git config --global user.email "[email protected]" |
| 35 | +
|
| 36 | + - name: Update version |
| 37 | + if: "github.event.inputs.releaseVersion != ''" |
| 38 | + run: | |
| 39 | + # Update development version if needed and commit |
| 40 | + echo "New development version is ${{ github.event.inputs.releaseVersion }}-SNAPSHOT" |
| 41 | + mvn -B versions:set -DnewVersion=${{ github.event.inputs.releaseVersion }}-SNAPSHOT |
| 42 | + git commit pom.xml -m "Updated development version to ${{ github.event.inputs.releaseVersion }}-SNAPSHOT" |
| 43 | +
|
| 44 | + - name: Tag version |
| 45 | + id: tag-version |
| 46 | + run: | |
| 47 | + # Get current development version |
| 48 | + CURRENT_DEV_VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` |
| 49 | + echo "Current development version is $CURRENT_DEV_VERSION" |
| 50 | + # Get release version |
| 51 | + RELEASE_VERSION=${CURRENT_DEV_VERSION%-SNAPSHOT} |
| 52 | + echo "Release version is $RELEASE_VERSION" |
| 53 | + # Update with release version, commit and push |
| 54 | + mvn -B versions:set -DnewVersion="${RELEASE_VERSION}" |
| 55 | + git commit pom.xml -m "Release ${RELEASE_VERSION}" |
| 56 | + git push |
| 57 | + # Tag and push |
| 58 | + git tag -a v$RELEASE_VERSION -m v$RELEASE_VERSION |
| 59 | + git push --follow-tags |
| 60 | + echo "::set-output name=releaseVersion::${RELEASE_VERSION}" |
| 61 | + echo "::set-output name=tagName::v${RELEASE_VERSION}" |
| 62 | +
|
| 63 | + - name: Create release |
| 64 | + uses: actions/create-release@v1 |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.PAT }} |
| 67 | + with: |
| 68 | + tag_name: ${{ steps.tag-version.outputs.tagName }} |
| 69 | + release_name: ${{ steps.tag-version.outputs.releaseVersion }} |
| 70 | + body: "Hosted on [Maven Central](https://search.maven.org/artifact/io.github.hectorbst/jsonschema2pojo-androidx-databinding/${{ steps.tag-version.outputs.releaseVersion }}/jar)." |
| 71 | + draft: false |
| 72 | + prerelease: false |
| 73 | + |
| 74 | + - name: Increment version |
| 75 | + run: | |
| 76 | + # Increment to next development version, get it, commit and push |
| 77 | + mvn -B org.apache.maven.plugins:maven-release-plugin:update-versions |
| 78 | + NEXT_DEV_VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout` |
| 79 | + echo "Next development is $NEXT_DEV_VERSION" |
| 80 | + git commit pom.xml -m "Started version ${NEXT_DEV_VERSION}" |
| 81 | + git push |
0 commit comments