Skip to content

Commit

Permalink
Add release flow (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
thepieterdc committed May 22, 2022
1 parent b64e42e commit 5bdb724
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 4 deletions.
17 changes: 17 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
changelog:
categories:
- title: "Features :star:"
labels:
- "feature"

- title: "Improvements :arrow_up:"
labels:
- "enhancement"

- title: "Bugfixes :bug:"
labels:
- "bug"

- title: "Maintenance :wrench:"
labels:
- "dependencies"
9 changes: 7 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
on: [push]
on: [pull_request, push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3

- run: sudo apt-get update

- run: sudo apt-get -y install libcurl4-openssl-dev

- run: cmake .

- run: make -j
9 changes: 7 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish Docker image
name: Publish snapshot image

on:
push:
Expand All @@ -8,13 +8,18 @@ on:
jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3

- name: Login to the container registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Download the latest image for caching
run: docker pull ghcr.io/thepieterdc/mailbridge:latest

- name: Build the new image
run: docker build . -t ghcr.io/thepieterdc/mailbridge:latest --cache-from ghcr.io/thepieterdc/mailbridge:latest

- name: Push the new image
run: docker push ghcr.io/thepieterdc/mailbridge:latest
124 changes: 124 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: Version number
required: true

jobs:
image:
name: Publish image to Docker registry

runs-on: ubuntu-latest

needs: prepare

permissions:
packages: write

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.version }}

- name: Login to the container registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin

- name: Download the latest snapshot image for caching
run: docker pull ghcr.io/thepieterdc/mailbridge:latest-snapshot

- name: Build the new image
run: docker build . -t ghcr.io/thepieterdc/mailbridge:latest -t ghcr.io/thepieterdc/mailbridge:${{ github.event.inputs.version }} --cache-from ghcr.io/thepieterdc/mailbridge:latest-snapshot

- name: Push the new image
run: docker push -a ghcr.io/thepieterdc/mailbridge

prepare:
name: Prepare the release

runs-on: ubuntu-latest

permissions:
contents: write

steps:
- uses: actions/checkout@v3

- name: Create a release branch
run: |
git checkout -b release
git push -u origin release
- name: Configure git
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Set the release version
run: ./scripts/set-version.sh ${{ github.event.inputs.version }}

- name: Make the release commit
uses: EndBug/add-and-commit@v9
with:
add: 'CMakeLists.txt'
branch: release
commit: '--signoff'
default_author: github_actions
message: "Release v${{ github.event.inputs.version }}"
tag: ${{ github.event.inputs.version }}

release:
name: Publish release

runs-on: ubuntu-latest

needs: prepare

permissions:
contents: write
pull-requests: write

steps:
- uses: actions/checkout@v3
with:
ref: release

- name: Configure git
run: |
git config user.email "[email protected]"
git config user.name "GitHub Actions"
- name: Create release
id: release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
draft: false
prerelease: false
release_name: ${{ github.event.inputs.version }}
tag_name: ${{ github.event.inputs.version }}

- name: Increase the version
run: ./scripts/increment-version.sh

- name: Make the next development commit
uses: EndBug/add-and-commit@v9
with:
add: 'CMakeLists.txt'
branch: release
commit: '--signoff'
default_author: github_actions
message: "Prepare the next development cycle"

- name: Open a pull request
uses: repo-sync/pull-request@v2
with:
destination_branch: master
github_token: ${{ secrets.GITHUB_TOKEN }}
pr_assignee: thepieterdc
pr_body: Merge the release commits into the main branch.
pr_title: Release v${{ github.event.inputs.version }}
source_branch: release
30 changes: 30 additions & 0 deletions scripts/increment-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

set -eu

usage() {
echo "Syntax: ./scripts/increment-version.sh"
exit 1
}

# Get the current version.
version=$(cat CMakeLists.txt | grep "mailbridge VERSION" | grep -o '".*"' | tr -d '"')

# Strip the optional -SNAPSHOT part.
if echo "$version" | grep -q "\-SNAPSHOT"; then
version=$(echo "$version" | sed "s/-SNAPSHOT//g")
fi

# Split the version.
major=$(echo "$version" | egrep -o "^[0-9]+")
minor=$(echo "$version" | egrep -o "\.[0-9]+\." | egrep -o "[0-9]+")
bugfix=$(echo "$version" | egrep -o "\.[0-9]+$" | egrep -o "[0-9]+")

# Increment the bugfix version.
bugfix=$((bugfix+1))

# Build the new version.
newversion="$major.$minor.$bugfix-SNAPSHOT"

# Set the new version.
./scripts/set-version.sh "$newversion"
16 changes: 16 additions & 0 deletions scripts/set-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

set -eu

usage() {
echo "Syntax: ./scripts/set-version.sh 1.0.0"
exit 1
}

# Check if the version argument was passed.
if [ "$#" -ne 1 ]; then
usage
fi

# Replace the version.
sed -i "s/mailbridge VERSION \".*\"/mailbridge VERSION \"$1\"/" CMakeLists.txt

0 comments on commit 5bdb724

Please sign in to comment.