From 95f4e35a0b7ad6da69f037e8c2a8d6498cea1bf3 Mon Sep 17 00:00:00 2001 From: Jonas Rebmann Date: Mon, 24 Nov 2025 17:07:42 +0100 Subject: [PATCH] CI: Add release workflow This github actions workflow will create a draft release for PRs that updates the version file. The commit message subject line must be Release microcom The commit message body will be used as release description. The release is converted from draft to an actual release, and the commit thereby tagged once the PR is merged. Signed-off-by: Jonas Rebmann --- .github/workflows/build.yml | 1 - .github/workflows/release-pr.yml | 102 +++++++++++++++++++++++++++++++ Makefile.am | 2 +- VERSION | 1 + configure.ac | 2 +- 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release-pr.yml create mode 100644 VERSION diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68ae1a5..6951edc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,3 @@ ---- name: Build test on: push: diff --git a/.github/workflows/release-pr.yml b/.github/workflows/release-pr.yml new file mode 100644 index 0000000..751fd51 --- /dev/null +++ b/.github/workflows/release-pr.yml @@ -0,0 +1,102 @@ +name: Draft Release + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + paths: + - VERSION + branches: [main] + +permissions: + contents: write + pull-requests: write + +jobs: + validate-release-commit: + if: > + !(github.event.pull_request.merged == true && + !contains(join(github.event.pull_request.labels.*.name), 'release')) + + runs-on: ubuntu-latest + + steps: + - name: Checkout merge + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get release commit info + id: version + run: | + ver=$(cat VERSION) + if ! echo "$ver" | grep -Eq '^[0-9]{4}\.[0-9]{2}\.[0-9]+$'; then + echo "Invalid version format: $ver" + exit 1 + fi + + echo "version=$ver" >> $GITHUB_OUTPUT + + headline="$(git show --format=%s ${{github.event.pull_request.head.sha}})" + if ! echo "$headline" | grep -Eq "^[Rr]elease microcom $ver$"; then + echo "Invalid commit headline: $headline" + exit 1 + fi + + body="$( + git show -s --format=%b ${{github.event.pull_request.head.sha}} \ + | sed -E '/^Signed-off-by: /d' + )" + + echo 'body<> $GITHUB_OUTPUT + echo "$body" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + - name: Install Dependencies + run: sudo apt install -y libreadline6-dev autoconf automake + + - name: Build release packages + run: | + autoreconf -i + ./configure + make check + make dist + + # DRAFT release on pr creation and update + - name: Create or update release draft + if: github.event.pull_request.merged == false + uses: softprops/action-gh-release@v2 + with: + draft: true + tag_name: v${{steps.version.outputs.version}} + name: microcom ${{steps.version.outputs.version}} + body: ${{steps.version.outputs.body}} + files: | + microcom-*.tar.gz + microcom-*.tar.xz + + # PUBLISH release on merge + - name: Publish release on merge + if: github.event.pull_request.merged == true + uses: softprops/action-gh-release@v2 + with: + draft: false + tag_name: v${{steps.version.outputs.version}} + files: | + microcom-*.tar.gz + microcom-*.tar.xz + + - run: gh pr edit "$NUMBER" --add-label "$LABELS" + if: github.event.pull_request.merged == false + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + GH_REPO: ${{github.repository}} + NUMBER: ${{github.event.pull_request.number}} + LABELS: release + + - run: gh pr comment "$NUMBER" --body "Release published!" + if: github.event.pull_request.merged == true + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} + GH_REPO: ${{github.repository}} + NUMBER: ${{github.event.pull_request.number}} + LABELS: release diff --git a/Makefile.am b/Makefile.am index e9fa3e6..57c44c5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ AUTOMAKE_OPTIONS = foreign ACLOCAL_AMFLAGS = -I m4 --install -EXTRA_DIST = DCO README.md +EXTRA_DIST = COPYING DCO README.md VERSION bin_PROGRAMS = microcom microcom_SOURCES = commands.c commands_fsl_imx.c microcom.c mux.c parser.c serial.c telnet.c diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..e4bd65b --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2023.09.0 diff --git a/configure.ac b/configure.ac index 2af4cd9..5d7484a 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([microcom], [2023.09.0], [oss-tools@pengutronix.de]) +AC_INIT([microcom], [m4_esyscmd_s(cat VERSION)], [oss-tools@pengutronix.de]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([dist-xz])