Skip to content

Commit

Permalink
Update ci-workflow.yml and create release.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciogeneroso committed Jun 30, 2024
1 parent cd40c86 commit 0a1e2d2
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ on:
- warning
- debug

env:
REGISTRY: ghcr.io
IMAGE_NAME: 'groot-mg/test/gateway'

jobs:
build-and-unit-tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -142,15 +138,19 @@ jobs:
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set repository basename
id: set-basename
run: echo "REPO_BASENAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
images: ghcr.io/groot-mg/test/${{ env.BASE_NAME }}
tags: |
type=sha
Expand Down
106 changes: 106 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: Release

on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'debug'
type: choice
options:
- info
- warning
- debug

env:
REGISTRY: ghcr.io
IMAGE_NAME: 'groot-mg/release/gateway'

jobs:
build-and-release:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Build
run: ./gradlew :app:build -x test

- name: Generate release version
run: ./gradlew :app:release

- name: Set repository basename
id: set-basename
run: echo "REPO_BASENAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Upload JAR
uses: actions/upload-artifact@v4
with:
name: app-jar
path: app/build/libs/${{ env.REPO_BASENAME }}.jar

publish-docker-image:
if: github.ref == 'refs/heads/main'
needs: build-and-release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

- name: Download JAR
uses: actions/download-artifact@v4
with:
name: app-jar
path: app/build/libs/

- name: Get version
id: get_version
run: |
VERSION=$(./gradlew app:currentVersion -q --console=plain | grep -oP '(?<=Project version: )[\d\.]+')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set repository basename
id: set-basename
run: echo "REPO_BASENAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/groot-mg/release/${{ env.BASE_NAME }}
tags: |
type=semver,prefix=v,pattern={{raw}},value=${{ env.VERSION }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: app/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit 0a1e2d2

Please sign in to comment.