From 5bdb72459b806a1b0675f64588d4ed2d46aeaa43 Mon Sep 17 00:00:00 2001 From: Pieter De Clercq Date: Sun, 22 May 2022 22:58:38 +0200 Subject: [PATCH] Add release flow (#19) --- .github/release.yml | 17 +++++ .github/workflows/build.yml | 9 ++- .github/workflows/publish.yml | 9 ++- .github/workflows/release.yml | 124 ++++++++++++++++++++++++++++++++++ scripts/increment-version.sh | 30 ++++++++ scripts/set-version.sh | 16 +++++ 6 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 .github/release.yml create mode 100644 .github/workflows/release.yml create mode 100755 scripts/increment-version.sh create mode 100755 scripts/set-version.sh diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..82e88e4 --- /dev/null +++ b/.github/release.yml @@ -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" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03c7fa5..3584e30 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fbb491b..6b36141 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Publish Docker image +name: Publish snapshot image on: push: @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7f05682 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 "actions@github.com" + 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 "actions@github.com" + 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 \ No newline at end of file diff --git a/scripts/increment-version.sh b/scripts/increment-version.sh new file mode 100755 index 0000000..dd99e2b --- /dev/null +++ b/scripts/increment-version.sh @@ -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" \ No newline at end of file diff --git a/scripts/set-version.sh b/scripts/set-version.sh new file mode 100755 index 0000000..1aefdc8 --- /dev/null +++ b/scripts/set-version.sh @@ -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 \ No newline at end of file