Skip to content

Commit

Permalink
Refactored to reuse GitHub Actions workflows
Browse files Browse the repository at this point in the history
To remove duplicate workflow config.
  • Loading branch information
freemanjp committed Aug 1, 2022
1 parent c8f2a2c commit fde323c
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 242 deletions.
105 changes: 4 additions & 101 deletions .github/workflows/build.yml
Expand Up @@ -3,109 +3,12 @@ on:
push:
branches:
- master
env:
JAVA_TOOL_OPTIONS: >-
-XX:TieredStopAtLevel=1
-XX:+UseParallelGC
-Dstyle.color=always
-Djansi.force=true

jobs:
build:
name: Maven build
runs-on: ubuntu-20.04
strategy:
matrix:
maven-version:
- '3.3.9'
- '3.6.1'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Build with Maven
run: .github/scripts/build.sh
env:
MAVEN_VERSION: ${{ matrix.maven-version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Code coverage report
if: matrix.maven-version == '3.6.1'
uses: codecov/codecov-action@v3.1.0

build-all:
if: ${{ always() }}
name: Build (matrix)
runs-on: ubuntu-20.04
needs: build
steps:
- name: Check build matrix status
run: "[[ '${{ needs.build.result }}' == 'success' ]] || exit 1"
uses: './.github/workflows/maven-build.yml'

deploy:
name: Maven deploy
runs-on: ubuntu-20.04
if: github.repository == 'gantsign/ktlint-maven-plugin'
needs: build-all
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}-deploy
restore-keys: |
${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Install GPG key
run: |-
gpg --batch --import-options import-show --import << EOF
${{ secrets.GPG_KEY }}
EOF
- name: Deploy with Maven
run: .github/scripts/deploy.sh
env:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete GPG secret key
if: ${{ always() }}
run: gpg --batch --yes --delete-secret-keys ${{ secrets.GPG_KEY_NAME }} || true
- name: Delete GPG public key
if: ${{ always() }}
run: gpg --batch --yes --delete-keys ${{ secrets.GPG_KEY_NAME }}
needs: build
uses: './.github/workflows/maven-deploy.yml'
secrets: inherit
51 changes: 51 additions & 0 deletions .github/workflows/maven-build.yml
@@ -0,0 +1,51 @@
name: Maven build
on:
workflow_call:
env:
JAVA_TOOL_OPTIONS: >-
-XX:TieredStopAtLevel=1
-XX:+UseParallelGC
-Dstyle.color=always
-Djansi.force=true
jobs:
build:
name: Maven build
runs-on: ubuntu-20.04
strategy:
matrix:
maven-version:
- '3.3.9'
- '3.6.1'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Build with Maven
run: .github/scripts/build.sh
env:
MAVEN_VERSION: ${{ matrix.maven-version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Code coverage report
if: matrix.maven-version == '3.6.1'
uses: codecov/codecov-action@v3.1.0
58 changes: 58 additions & 0 deletions .github/workflows/maven-deploy.yml
@@ -0,0 +1,58 @@
name: Maven deploy
on:
workflow_call:
env:
JAVA_TOOL_OPTIONS: >-
-XX:TieredStopAtLevel=1
-XX:+UseParallelGC
-Dstyle.color=always
-Djansi.force=true
jobs:
deploy:
name: Maven deploy
runs-on: ubuntu-20.04
if: github.repository == 'gantsign/ktlint-maven-plugin'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}-deploy
restore-keys: |
${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Install GPG key
run: |-
gpg --batch --import-options import-show --import << EOF
${{ secrets.GPG_KEY }}
EOF
- name: Deploy with Maven
run: .github/scripts/deploy.sh
env:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete GPG secret key
if: ${{ always() }}
run: gpg --batch --yes --delete-secret-keys ${{ secrets.GPG_KEY_NAME }} || true
- name: Delete GPG public key
if: ${{ always() }}
run: gpg --batch --yes --delete-keys ${{ secrets.GPG_KEY_NAME }}
99 changes: 4 additions & 95 deletions .github/workflows/release.yml
Expand Up @@ -12,103 +12,12 @@ env:
jobs:
build:
name: Maven build
runs-on: ubuntu-20.04
strategy:
matrix:
maven-version:
- '3.3.9'
- '3.6.1'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Build with Maven
run: .github/scripts/build.sh
env:
MAVEN_VERSION: ${{ matrix.maven-version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Code coverage report
if: matrix.maven-version == '3.6.1'
uses: codecov/codecov-action@v3.1.0

build-all:
if: ${{ always() }}
name: Build (matrix)
runs-on: ubuntu-20.04
needs: build
steps:
- name: Check build matrix status
run: "[[ '${{ needs.build.result }}' == 'success' ]] || exit 1"
uses: './.github/workflows/maven-build.yml'

deploy:
name: Maven deploy
runs-on: ubuntu-20.04
if: github.repository == 'gantsign/ktlint-maven-plugin'
needs: build-all
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}-deploy
restore-keys: |
${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Install GPG key
run: |-
gpg --batch --import-options import-show --import << EOF
${{ secrets.GPG_KEY }}
EOF
- name: Deploy with Maven
run: .github/scripts/deploy.sh
env:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GPG_KEY_NAME: ${{ secrets.GPG_KEY_NAME }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Delete GPG secret key
if: ${{ always() }}
run: gpg --batch --yes --delete-secret-keys ${{ secrets.GPG_KEY_NAME }} || true
- name: Delete GPG public key
if: ${{ always() }}
run: gpg --batch --yes --delete-keys ${{ secrets.GPG_KEY_NAME }}
needs: build
uses: './.github/workflows/maven-deploy.yml'
secrets: inherit

deploy-site:
name: Maven deploy site
Expand Down
47 changes: 1 addition & 46 deletions .github/workflows/verify.yml
Expand Up @@ -3,54 +3,9 @@ name: Verify
on:
pull_request:

env:
JAVA_TOOL_OPTIONS: >-
-XX:TieredStopAtLevel=1
-XX:+UseParallelGC
-Dstyle.color=always
-Djansi.force=true
jobs:
build:
name: Maven build
runs-on: ubuntu-20.04
strategy:
matrix:
maven-version:
- '3.3.9'
- '3.6.1'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: 8
distribution: 'temurin'
# Since code changes to this project are infrequent, and most commits
# change the pom.xml, we cache by date interval rather than file hash.
- name: Calculate cache interval
run: |
leveler="$(wc -c <<< "$GITHUB_REPOSITORY")"
echo "::set-output name=CACHE_INTERVAL::$(date +%Y)-$(($(($leveler + $(date +%-j))) / 30))"
id: cache-interval
- name: Cache local Maven repository
uses: actions/cache@v3
with:
path: |
~/.m2/repository
!~/.m2/repository/com/github/gantsign/maven
key: ${{ runner.os }}-maven-${{ steps.cache-interval.outputs.CACHE_INTERVAL }}
- name: Build with Maven
run: .github/scripts/build.sh
env:
MAVEN_VERSION: ${{ matrix.maven-version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Code coverage report
if: matrix.maven-version == '3.6.1'
uses: codecov/codecov-action@v3.1.0
uses: './.github/workflows/maven-build.yml'

build-all:
if: ${{ always() }}
Expand Down

0 comments on commit fde323c

Please sign in to comment.