Skip to content

Commit

Permalink
feature: add release github action
Browse files Browse the repository at this point in the history
  • Loading branch information
lmoesle committed Mar 27, 2024
1 parent 4264f82 commit bc9742b
Show file tree
Hide file tree
Showing 8 changed files with 238 additions and 75 deletions.
18 changes: 18 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
changelog:
categories:
- title: 🎉 New Features
labels:
- feature
- title: 🐞 Bug Fixes
labels:
- bug
- title: 🔨 Refactoring
labels:
- refactoring
- title: 📔 Documentation
labels:
- docs
- title: 🛠️ Misc
labels:
- Technical Debt
- chore
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ jobs:
release-version: dev
snapshot-release: true
maven-release: false
docker-release: ${{ github.ref_name == 'dev' }}
# FIXME rename the feat/new_platform branch
# docker-release: ${{ github.ref_name == 'dev' }}
docker-release: ${{ github.ref_name == 'feat/new_platform' }}
secrets: inherit

labelPR:
Expand Down
71 changes: 0 additions & 71 deletions .github/workflows/publish.yml

This file was deleted.

51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release

on:
workflow_dispatch:
inputs:
release-tag:
description: 'Release Tag'
required: false
default: 'services_XXX_apps_XXX'
maven-new-version:
description: '(Optional) Specify new maven version - SNAPSHOT will be added to the version'
required: false

jobs:
release-version:
runs-on: ubuntu-latest
steps:
- uses: PREP / actions/checkout@v4
- name: PREP / Prepare mvnw
run: chmod +x ./mvnw
- name: PREP / Remove snapshot from services
run: ./mvnw versions:set --batch-mode -DremoveSnapshot -DprocessAllModules
- name: PREP / Set services release version env variable
run: echo "SERVICES_RELEASE_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
outputs:
services-release-version: ${{ env.SERVICES_RELEASE_VERSION }}

release-services:
needs: release-version
uses: ./.github/workflows/workflow-build-and-release-services.yml
with:
release-version: ${{ needs.release-version.outputs.services-release-version }}
snapshot-release: false
maven-release: true
docker-release: true
secrets: inherit

github-release:
needs: release-services
uses: ./.github/workflows/workflow-github-release.yaml
with:
release-tag: ${{ github.event.inputs.release-tag }}
secrets: inherit

bump-versions:
needs: github-release
uses: ./.github/workflows/workflow-bump-version.yaml
with:
new-maven-version: ${{ github.event.inputs.maven-new-version }}
secrets: inherit

15 changes: 12 additions & 3 deletions .github/workflows/workflow-build-and-release-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,30 @@ jobs:
chmod +x ./mvnw
./mvnw --batch-mode clean install
- name: RELEASE / Build and Release Maven
- name: RELEASE / Remove SNAPSHOT
if: inputs.maven-release == true
# TODO other command
run: |
chmod +x ./mvnw
./mvnw --batch-mode clean install
./mvnw versions:set --batch-mode -DremoveSnapshot -DprocessAllModules
- name: RELEASE / Build and Release Maven
if: inputs.maven-release == true
uses: samuelmeuli/action-maven-publish@v1
with:
gpg_private_key: ${{ secrets.pgp_private_key }}
gpg_passphrase: ${{ secrets.pgp_private_key_secret }}
nexus_username: ${{ secrets.nexus_username }}
nexus_password: ${{ secrets.nexus_password }}

- name: DOCKER / BUILD & PUBLISH / miragon/miranum-camunda7-engine-service
if: inputs.docker-release == true
uses: docker/build-push-action@v5
with:
context: ./platform/services/miragon/camunda7-engine-service/.
push: true
tags: miragon/miranum-camunda7-engine-service:${{ env.RELEASE_VERSION }}
platforms: linux/amd64, linux/arm64/v8
- name: DOCKER / BUILD & PUBLISH / miragon/miranum-deployment-service
if: inputs.docker-release == true
uses: docker/build-push-action@v5
with:
context: ./platform/services/deployment-service/.
Expand Down
77 changes: 77 additions & 0 deletions .github/workflows/workflow-bump-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Bump version

on:
workflow_call:
inputs:
new-maven-version:
description: 'New maven version'
type: string
required: false
workflow_dispatch:
inputs:
new-maven-version:
description: 'New maven version'
type: string
required: false

jobs:
bump-versions:
name: Bumps versions
runs-on: ubuntu-latest
steps:
- name: PREP / Checkout code
uses: actions/checkout@v4
- name: PREP / Setup git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Miranum Github Bot"
- name: PREP / Prepare mvnw
run: chmod +x ./mvnw
- name: PREP / Install Java and Maven
if: inputs.bump-services-version== true
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'

- name: BUMP VERSION / Raise mvn version
if: inputs.new-maven-version != ''
run: |
./mvnw versions:set --batch-mode -DprocessAllModules -DnewVersion=${{ inputs.new-maven-version }}-SNAPSHOT -DprocessAllModules
./mvnw versions:commit -DprocessAllModules
- name: BUMP VERSION / Raise mvn version
if: inputs.new-maven-version == ''
run: |
./mvnw build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.nextMinorVersion}.0-SNAPSHOT -DprocessAllModules
./mvnw versions:commit -DprocessAllModules
- name: GIT / Git commit
run: |
git add .
git commit -m "chore: mvn auto version bump to $(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)"
- name: GIT / Push changes to new branch
run: |
git checkout -b ${{ github.ref_name }}-version-bump
git push --force origin ${{ github.ref_name }}-version-bump
- name: GIT / Create pull request
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
const pullResult = await github.rest.pulls.create({
title: 'chore: bump release version ${{ github.ref_name }}',
owner,
repo,
head: '${{ github.ref_name }}-version-bump',
base: '${{ github.ref_name }}',
body: [
'This PR is auto-generated'
].join('\n')
});
await github.rest.issues.addAssignees({
owner,
repo,
issue_number: pullResult.data.number,
assignees: ['${{ github.actor }}'],
});
console.log(`Pull Request created: ${pullResult.data.html_url}`);
36 changes: 36 additions & 0 deletions .github/workflows/workflow-github-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Github Release

on:
workflow_call:
inputs:
release-tag:
description: 'Release tag'
type: string
required: true

jobs:
github-release:
name: Create Release
runs-on: ubuntu-latest
steps:
- name: PREP / Checkout code
uses: actions/checkout@v4

- name: GIT / Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ inputs.release-tag }}',
sha: context.sha
})
- name: GIT / Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release-tag }}
draft: false
prerelease: false
generate_release_notes: true
41 changes: 41 additions & 0 deletions docs/CICD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# CICD

We use GitHub Actions for CICD Pipelines. The pipelines are defined in the `.github/workflows` directory.

## Workflows

### Build

**Feature Branches**

Build the project using Maven on each commit and PR to the `main` branch.

```mermaid
graph LR
A[Checkout] --> B[Maven Build]
```

**Main Branch**

Every new commit to the `main` branch builds the project using Maven and builds and releases Docker Images to Docker Hub with the tag `dev`.

```mermaid
graph LR
A[Checkout] --> B[Maven Build]
B --> C[Docker Build and Push]
```

### Release

Releases are triggered by dispatching the Release workflow manually.
The release workflow creates a new maven release and builds and releases Docker Images to Docker Hub with a version tag.
Additionally, a GitHub Release is created with auto generated release notes and finally the Maven version is bumped to the next snapshot version (or the version specified with the workflow dispatch).

```mermaid
graph LR
A[Checkout] --> B[Maven Build and Release]
B --> C[Docker Build and Push]
C --> D[Github Release]
D --> E[Maven Version Bump]
```

0 comments on commit bc9742b

Please sign in to comment.