Skip to content

Commit

Permalink
Merge pull request #319 from liquibase/feature/DAT-4607
Browse files Browse the repository at this point in the history
Extension Release Automation
  • Loading branch information
r2-lf committed May 10, 2021
2 parents ec90bac + b7a0bee commit c1af71b
Show file tree
Hide file tree
Showing 11 changed files with 599 additions and 163 deletions.
26 changes: 26 additions & 0 deletions .github/add-comment-to-pull-request.sh
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -ex
set -o pipefail

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

if [[ -z "$GITHUB_ISSUE_URL" ]]; then
echo "Set the GITHUB_ISSUE_URL env variable."
exit 1
fi

if [[ -z "$GITHUB_COMMENT" ]]; then
echo "Set the GITHUB_COMMENT env variable."
exit 1
fi

data='{"body":"'${GITHUB_COMMENT}'"}'

#Create Label on Pull Request
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
--data "$data" \
"$GITHUB_ISSUE_URL/comments"
26 changes: 26 additions & 0 deletions .github/add-label-to-pull-request.sh
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

set -e
set -o pipefail

if [[ -z "$GITHUB_TOKEN" ]]; then
echo "Set the GITHUB_TOKEN env variable."
exit 1
fi

if [[ -z "$GITHUB_ISSUE_URL" ]]; then
echo "Set the GITHUB_ISSUE_URL env variable."
exit 1
fi

if [[ -z "$GITHUB_LABEL" ]]; then
echo "Set the GITHUB_LABEL env variable."
exit 1
fi

data='["'${GITHUB_LABEL}'"]'

#Create Label on Pull Request
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
--data "$data" \
"$GITHUB_ISSUE_URL/labels"
13 changes: 0 additions & 13 deletions .github/dependabot.yml
Expand Up @@ -5,16 +5,3 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: org.hibernate:hibernate-envers
versions:
- 5.4.27.Final
- 5.4.29.Final
- dependency-name: org.hibernate:hibernate-entitymanager
versions:
- 5.4.27.Final
- 5.4.29.Final
- dependency-name: org.hibernate:hibernate-core
versions:
- 5.4.27.Final
- 5.4.29.Final
13 changes: 13 additions & 0 deletions .github/set-version-from-head.sh
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e
set -o pipefail

HEAD_REF=$1

if [[ -z "$HEAD_REF" ]]; then
echo "Set the HEAD_REF parameter"
exit 1
fi

echo "VERSION_TAG=${HEAD_REF#*org.liquibase-liquibase-core-}" >> $GITHUB_ENV
6 changes: 6 additions & 0 deletions .github/set-version-from-pom.sh
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -e
set -o pipefail

echo "VERSION_TAG=$(mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
136 changes: 136 additions & 0 deletions .github/workflows/pull-request-labeled-closed.yml
@@ -0,0 +1,136 @@
name: Prepare Release Candidate for Release

on:
pull_request:
types:
- closed

jobs:
verify:
name: Verify Closed PR is Release Candidate
runs-on: ubuntu-latest
if: |
${{ github.ref == 'main' }} &&
${{ github.event.pull_request.merged }} &&
contains( github.event.pull_request.labels.*.name, 'Extension Release Candidate :rocket:' )
steps:
- run: echo "Starting Release ... "

build:
needs: [verify]
name: Build Artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
server-id: sonatype-nexus-staging
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SECRET }}
gpg-passphrase: GPG_PASSPHRASE

- name: Build With Maven
run: mvn clean install -Dmaven.test.skip
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: liquibase-hibernate5
path: target/*.jar

draft-release:
needs: [ build ]
name: Draft Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Set Version Tag ENV from POM
run: ./.github/set-version-from-pom.sh

- run: echo ::set-output name=version::$VERSION_TAG
id: version

- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: liquibase-hibernate5

- name: Release
uses: softprops/action-gh-release@v1
with:
target_commitish: ${{ github.sha }}
name: v${{ steps.version.outputs.version }}
tag_name: liquibase-hibernate5-${{ steps.version.outputs.version }}
draft: true
body: Support for Liquibase ${{ steps.version.outputs.version }}.
files: liquibase-hibernate5-*.jar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

bump-pom-to-snapshot:
name: Prepare POM for Development
runs-on: ubuntu-latest
needs: [ draft-release ]
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Configure git user
run: |
git config user.name "liquibot"
git config user.email "liquibot@liquibase.org"
- name: Bump POM Version for Development
run: |
mvn versions:set -DnextSnapshot=true
git add pom.xml
git commit -m "Version Bumped to Snapshot for Developent"
git push "https://liquibot:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:${{ github.base_ref }} --follow-tags --tags
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/pull-request-labeled-release.yml
@@ -0,0 +1,33 @@
name: Build, Test, and Prepare Release Candidate

on:
pull_request:
types:
- labeled
- reopened
- synchronize

jobs:
integration-tests:
name: Java ${{ matrix.java }}
runs-on: ubuntu-latest
if: contains( github.event.pull_request.labels.*.name, 'Extension Release Candidate :rocket:' )
strategy:
matrix:
java: [8, 11, 16]
steps:
- uses: actions/checkout@v2
- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- name: Test With Maven
run: mvn clean verify --file pom.xml
94 changes: 94 additions & 0 deletions .github/workflows/pull-request.yml
@@ -0,0 +1,94 @@
name: Run Unit Tests

on:
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
unit-test:
name: Java ${{ matrix.java }}
runs-on: ubuntu-latest
# Only run job if untagged as release. Will run for all PRs and release PRs during the first run.
if: ${{ !contains( github.event.pull_request.labels.*.name, 'Extension Release Candidate :rocket:' ) }}
strategy:
matrix:
java: [8, 11, 16]

steps:
- uses: actions/checkout@v2
- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK ${{ matrix.java }}
uses: actions/setup-java@v2
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- name: Run Unit Tests With Maven
run: mvn surefire:test --file pom.xml

# This step is the automation to create a release based on a liquibase core bump
# If a manual release is required, the steps below will need to be done manually prior
# to adding the Release Candidate label.
label:
name: Label as Release Candidate
runs-on: ubuntu-latest
needs: [ unit-test ]
if: contains( github.event.pull_request.head.ref, 'dependabot/maven/org.liquibase-liquibase-core' )
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

- name: Cache Local Maven Repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'

- name: Set Version Tag ENV
run: ./.github/set-version-from-head.sh ${{ github.event.pull_request.head.ref }}

- run: echo $VERSION_TAG

- name: Configure git user
run: |
git config user.name "liquibot"
git config user.email "liquibot@liquibase.org"
- name: Bump POM Version for Next Release
run: |
mvn versions:set -DnewVersion=$VERSION_TAG
git add pom.xml
git commit -m "Version Bumped to $VERSION_TAG"
git tag -a -m "Version Bumped to $VERSION_TAG" liquibase-hibernate5-$VERSION_TAG
git push "https://liquibot:$GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git" HEAD:${{ github.event.pull_request.head.ref }} --follow-tags --tags
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}

- run: ./.github/add-label-to-pull-request.sh
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
GITHUB_ISSUE_URL: ${{ github.event.pull_request._links.issue.href }}
GITHUB_LABEL: "Extension Release Candidate :rocket:"
- run: ./.github/add-comment-to-pull-request.sh
env:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
GITHUB_ISSUE_URL: ${{ github.event.pull_request._links.issue.href }}
GITHUB_COMMENT: "<h2> ⚠️ Reminder</h2>Release Candidate pull requests will automatically release when merged.<br /><br />Please review and merge all other pull requests prior to merging this request."
29 changes: 29 additions & 0 deletions .github/workflows/release-published.yml
@@ -0,0 +1,29 @@
name: Release Extension to Sonatype

on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Java for publishing to Maven Central Repository
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
server-id: sonatype-nexus-staging
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.GPG_SECRET }}
gpg-passphrase: GPG_PASSPHRASE

- name: Publish to the Maven Central Repository
run: mvn clean deploy -Dmaven.test.skip -P release
env:
MAVEN_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

0 comments on commit c1af71b

Please sign in to comment.