Skip to content

Commit

Permalink
Merge pull request #22 from Kochava/gradle-jvm
Browse files Browse the repository at this point in the history
add gradle jvm workflows
  • Loading branch information
otternq authored Feb 27, 2023
2 parents 5334689 + e7274c4 commit 759476a
Showing 3 changed files with 243 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/gradle_jvm_app_pull_requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Pull Request
on:
workflow_call:
inputs:
GH_CI_USER:
description: 'User for GitHub auth'
required: true
type: string
JAVA_VERSION:
required: false
type: string
default: 17
secrets:
GH_CI_PAT:
description: 'Token password for GitHub auth'
required: true
jobs:
commitlint:
#
# ensures commit messages follow conventional commits
#
runs-on: ubuntu-latest
steps:
# checkout the commits to lint.
- uses: actions/checkout@v3
with:
fetch-depth: 0
# setup node, needed to lint commits.
- uses: actions/setup-node@v1
with:
node-version: 18
# Install needed libraries to lint commits.
- run: npm install --save-dev @commitlint/{config-conventional,cli}
# Lint the commits.
- run: npx commitlint --from=${{ github.event.pull_request.base.sha }}
docker-build:
#
# ensures the docker image will build without pushing to the registry
# uses the git sha for the most recent commit for the version
#
runs-on: ubuntu-latest
steps:
# Checkout code to build.
- name: Checkout repo
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ inputs.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Execute Gradle Assemble
run: ./gradlew assemble
# Setup docker build arguments.
- name: Docker release meta
id: release
uses: docker/metadata-action@v4
with:
images: |
${{ github.repository }}
tags: |
type=sha
# Setup Docker builder to do build.
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Build the app.
- name: Build
uses: docker/build-push-action@v3
with:
push: false
provenance: false
context: .
file: Dockerfile
platforms: linux/amd64
tags: ${{ steps.release.outputs.tags }}
39 changes: 39 additions & 0 deletions .github/workflows/gradle_jvm_app_push_main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create Github Release

on:
workflow_call:
secrets:
GH_CI_PAT:
description: 'Token password for GitHub auth'
required: true

jobs:
release:
#
# Create a GitHub Release based on conventional commits.
#
name: 'Release to GitHub'
runs-on: ubuntu-latest
steps:
# Checkout code to release.
- name: Checkout repo
uses: actions/checkout@v3
# Setup Node needed to create release.
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 18
# Add plugin to make the changelog for the release.
- name: Add plugin for conventional commits
run: npm install conventional-changelog-conventionalcommits
working-directory: ./.github/workflows
# Create the release.
- name: Release to GitHub
working-directory: ./.github/workflows
env:
GITHUB_TOKEN: ${{ secrets.GH_CI_PAT }}
GIT_AUTHOR_NAME: release-bot
GIT_AUTHOR_EMAIL: release@test.com
GIT_COMMITTER_NAME: asyncapi-bot
GIT_COMMITTER_EMAIL: info@asyncapi.io
run: npx semantic-release
128 changes: 128 additions & 0 deletions .github/workflows/gradle_jvm_app_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Release Docker Version

on:
workflow_call:
inputs:
GH_CI_USER:
description: 'User for GitHub auth'
required: true
type: string
JAVA_VERSION:
required: false
type: string
default: 17
secrets:
GH_CI_PAT:
description: 'Token password for GitHub auth'
required: true

# Registry arguments.
# Must supply set of arguments for at least 1 registry.

# Artifact Registry arguments
ARTIFACT_REGISTRY:
description: 'Artifact Registry address to which to publish (leave blank to not publish)'
required: false
ARTIFACT_REGISTRY_JSON_KEY:
description: 'Key for publishing to Artifact Registry'
required: false
# Container Registry arguements
CONTAINER_REGISTRY:
description: 'Container Registry address to which to publish (leave blank to not publish)'
required: false
CONTAINER_REGISTRY_JSON_KEY:
description: 'Key for publishing to Container Registry'
required: false

env:
GOPRIVATE: ${{ inputs.GOPRIVATE }}

jobs:
push:
#
# Build the Docker image artifact and deliver it.
#
runs-on: ubuntu-latest
steps:
# Checkout code needed to build docker image.
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ inputs.JAVA_VERSION }}
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
- name: Execute Gradle Assemble
run: ./gradlew assemble
# Parse GitHub repository name for use in constructing docker image names.
- name: Parse Repo Name
id: parse_repo_name
run: |
echo "repo_name=$( echo '${{ github.repository }}' | awk -F '/' '{print $2}' )" >> $GITHUB_OUTPUT
# Make the docker fields for Artifact Registry if we're pushing to it.
- name: Construct Artifact Registry fields
env:
ARTIFACT_REGISTRY: ${{ secrets.ARTIFACT_REGISTRY }}
if: ${{ env.ARTIFACT_REGISTRY }}
run: |
echo "ARTIFACT_REGISTRY_IMAGE_NAME=${{ secrets.ARTIFACT_REGISTRY }}/${{ github.repository }}" >> $GITHUB_ENV
# Make the docker fields for Container Registry if we're pushing to it.
- name: Construct Container Registry fields
env:
CONTAINER_REGISTRY: ${{ secrets.CONTAINER_REGISTRY }}
if: ${{ env.CONTAINER_REGISTRY }}
run: |
echo "CONTAINER_REGISTRY_IMAGE_NAME=${{ secrets.CONTAINER_REGISTRY }}/${{ steps.parse_repo_name.outputs.repo_name }}" >> $GITHUB_ENV
# Create docker image meta data. Docker tags include the Git tag itself and the sematic version parsing of that tag if possible.
- name: Docker release meta
id: release
uses: docker/metadata-action@v4
with:
images: |
${{ env.ARTIFACT_REGISTRY_IMAGE_NAME }}
${{ env.CONTAINER_REGISTRY_IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=ref,event=tag
type=semver,pattern={{version}}
# Login to Artifact Registry if we're pushing to it.
- name: Login to Artifact Registry
env:
ARTIFACT_REGISTRY_JSON_KEY: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }}
if: ${{ env.ARTIFACT_REGISTRY_JSON_KEY }}
uses: docker/login-action@v2
with:
registry: ${{ secrets.ARTIFACT_REGISTRY }}
username: _json_key
password: ${{ secrets.ARTIFACT_REGISTRY_JSON_KEY }}
# Login to Container Registry if we're pushing to it.
- name: Login to Container Registry
env:
CONTAINER_REGISTRY_JSON_KEY: ${{ secrets.CONTAINER_REGISTRY_JSON_KEY }}
if: ${{ env.CONTAINER_REGISTRY_JSON_KEY }}
uses: docker/login-action@v2
with:
registry: ${{ secrets.CONTAINER_REGISTRY }}
username: _json_key
password: ${{ secrets.CONTAINER_REGISTRY_JSON_KEY }}
# Setup QEMU needed to build arm64 images.
- name: Setup QEMU
uses: docker/setup-qemu-action@v2
# Setup Docker builder needed to build multi-architectural images.
- name: Setup Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
# Build and push the image.
- name: Build and Push to Artifact Registry and Container Registry
uses: docker/build-push-action@v3
with:
push: true
provenance: false
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ steps.release.outputs.version }}
tags: ${{ steps.release.outputs.tags }}
labels: ${{ steps.release.outputs.labels }}

0 comments on commit 759476a

Please sign in to comment.