Skip to content

Commit

Permalink
add semantic versioning enforcement to repo
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzel-felix committed Feb 18, 2024
1 parent c86d837 commit c3d0701
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 40 deletions.
1 change: 1 addition & 0 deletions .github/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
titleOnly: true
57 changes: 57 additions & 0 deletions .github/workflows/check-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Check Release
on:
pull_request:
types: [opened, edited, reopened, synchronize]

permissions:
contents: write
pull-requests: read

jobs:
check-release:
name: Check Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'
- name: Adding PR commit message
run: |
echo "Checking PR title for $GITHUB_HEAD_REF based PR..."
squash_commit_name=$(gh pr view $GITHUB_HEAD_REF --json title -q '.title')
git config --global user.email $(git log -1 --pretty=format:'%ae')
git config --global user.name $(git log -1 --pretty=format:'%an')
git commit --amend -m "$squash_commit_name"
env:
GH_TOKEN: ${{ github.token }}
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
- name: Create Release
run: |
latest_tag=$(git tag -l --sort -version:refname | head -n 1)
echo "Latest tag: $latest_tag"
upcoming_tag="v${{ steps.gitversion.outputs.GitVersion_MajorMinorPatch }}"
echo "Upcoming tag: $upcoming_tag"
if [ -z "$(git tag -l | grep $upcoming_tag)" ]; then
echo "Version does not clash with any existing tag"
echo "$upcoming_tag is the new version to release"
else
echo "The version clashes with an existing tag"
exit 1
fi
if [ "$latest_tag" != "$upcoming_tag" ]; then
echo "Version does not clash with the latest created tag"
echo "$upcoming_tag is the new version to release"
else
echo "The version clashes with the latest created tag"
exit 1
fi
72 changes: 33 additions & 39 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -1,50 +1,44 @@
name: Init Release
name: Release
on:
workflow_dispatch:
inputs:
TARGET_VERSION:
description: 'TARGET_VERSION to build manifests (e.g. 2.5.0-rc1) Note: the `v` prefix is not used'
required: true
type: string
push:
branches:
- main

permissions:
contents: write
pull-requests: read

jobs:
init-release:
name: Create new release for ${{ inputs.TARGET_VERSION }}
runs-on: ubuntu-22.04
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main

- name: Check if TARGET_VERSION is well formed.
run: |
set -xue
# Target version must not contain 'v' prefix
if echo "${{ inputs.TARGET_VERSION }}" | grep -e '^v'; then
echo "::error::Target version '${{ inputs.TARGET_VERSION }}' should not begin with a 'v' prefix, refusing to continue." >&2
exit 1
fi
- name: Create release v${{ inputs.TARGET_VERSION }}
run: |
gh release create v${{ inputs.TARGET_VERSION }} --generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Login to GitHub Container Registry"
uses: docker/login-action@v1
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}

- name: Set env
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0
- name: Create Release
run: |
echo "RELEASE_VERSION=${{ inputs.TARGET_VERSION }}" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
echo "Creating release for $GITHUB_HEAD_REF based PR..."
Version="${{ steps.gitversion.outputs.GitVersion_MajorMinorPatch }}"
echo "Version: $Version"
author=$(git log -1 --pretty=format:'%an')
echo "Author: $author"
email=$(git log -1 --pretty=format:'%ae')
echo "Email: $email"
git config --global user.email $email
git config --global user.name $author
git tag -a "v$Version" -m "v$Version"
git push origin "v$Version"
echo "RELEASE_VERSION=v$Version" >> $GITHUB_ENV
- name: Build and push to ghcr.io with tag latest and ${{ inputs.TARGET_VERSION }}
uses: docker/build-push-action@v5
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ on:
branches:
- main
paths-ignore:
- '.github/workflows/*'
- '.github/*'
- .dockerignore
- .gitignore
- GitVersion.yml
- LICENSE
- README.md

permissions:
id-token: write
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push-helm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
paths:
- ".github/workflows/push-helm.yaml"
- "charts/**"
workflow_dispatch:

jobs:
release:
Expand Down
6 changes: 6 additions & 0 deletions GitVersion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mode: Mainline
major-version-bump-message: '(feat|fix)(\(.*\))?!:'
minor-version-bump-message: 'feat(\(.*\))?:'
patch-version-bump-message: 'fix(\(.*\))?:'
no-bump-message: '(none|skip|test|refactor|docs|build|ci|style)(\(.*\))?:'
commit-message-incrementing: Disabled

0 comments on commit c3d0701

Please sign in to comment.