Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate release process #124

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .github/release.yml

# Configure automatic release note generation
# See https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes
changelog:
exclude:
labels:
- ignore-for-release
97 changes: 97 additions & 0 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Create draft release

on:
workflow_dispatch:
inputs:
release_type:
description: 'Release Type'
required: true
default: 'minor'
type: choice
options:
- major
- minor
- patch

jobs:
Create-Release:
runs-on: ubuntu-latest

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write

outputs:
release_url: ${{ steps.create-draft-release.outputs.url }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Update the version
id: bump_version
shell: pwsh
run: |
# Extract current version
$header = Get-Content ./libdivide.h
$major_ver = [int](($header -match "LIBDIVIDE_VERSION_MAJOR")[0] -Split " ")[-1]
$minor_ver = [int](($header -match "LIBDIVIDE_VERSION_MINOR")[0] -Split " ")[-1]
$patch_ver = [int](($header -match "LIBDIVIDE_VERSION_PATCH")[0] -Split " ")[-1]
$current_version=@($major_ver, $minor_ver, $patch_ver) -Join "."

# Increment version
if ("${{ github.event.inputs.release_type }}" -eq "patch") {
$patch_ver = $patch_ver + 1
} elseif ("${{ github.event.inputs.release_type }}" -eq "minor") {
$minor_ver = $minor_ver + 1
$patch_ver = 0
} else { # Must be major version
$major_ver = $major_ver + 1
$minor_ver = 0
$patch_ver = 0
}
$new_version=@($major_ver, $minor_ver, $patch_ver) -Join "."

# Update header file
$header = $header -replace "#define LIBDIVIDE_VERSION_MAJOR \d+", "#define LIBDIVIDE_VERSION_MAJOR $major_ver"
$header = $header -replace "#define LIBDIVIDE_VERSION_MINOR \d+", "#define LIBDIVIDE_VERSION_MINOR $minor_ver"
$header = $header -replace "#define LIBDIVIDE_VERSION_PATCH \d+", "#define LIBDIVIDE_VERSION_PATCH $patch_ver"
$header | Set-Content ./libdivide.h

# Update other files
$file="./library.properties"
$regex = 'version=(\d+\.\d+(\.\d+)?)'
(Get-Content $file) -replace $regex, "version=$new_version" | Set-Content $file

$file="./CMakeLists.txt"
$regex = "set\(LIBDIVIDE_VERSION ""\d+\.\d+(\.\d+)?""\)"
(Get-Content $file) -replace $regex, "set(LIBDIVIDE_VERSION ""$new_version"")" | Set-Content $file

Write-Output "previous_version=$current_version" >> $Env:GITHUB_OUTPUT
Write-Output "version=$new_version" >> $Env:GITHUB_OUTPUT
Write-Output "major=$major_ver" >> $Env:GITHUB_OUTPUT
Write-Output "minor=$minor_ver" >> $Env:GITHUB_OUTPUT
Write-Output "patch=$patch_ver" >> $Env:GITHUB_OUTPUT

# Commit all changed files back to the repository
- name: Checkout code
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Auto increment version to ${{ steps.bump_version.outputs.version }}

# Create draft release
- name: Create draft release
id: create-draft-release
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.bump_version.outputs.version }}
draft: true
generate_release_notes: true
tag_name: v${{ steps.bump_version.outputs.version }}

- name: Generate Summary
run: |
echo "Created [v${{ steps.bump_version.outputs.version }} draft release](${{ steps.create-draft-release.outputs.url }})" >> $GITHUB_STEP_SUMMARY
5 changes: 4 additions & 1 deletion libdivide.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#ifndef LIBDIVIDE_H
#define LIBDIVIDE_H

#define LIBDIVIDE_VERSION "5.1"
#define LIBDIVIDE_VERSION_MAJOR 5
#define LIBDIVIDE_VERSION_MINOR 1
#define LIBDIVIDE_VERSION_PATCH 0
#define LIBDIVIDE_STR_INNER(s) #s
#define LIBDIVIDE_STR(s) LIBDIVIDE_STR_INNER(s)
#define LIBDIVIDE_VERSION (LIBDIVIDE_STR(LIBDIVIDE_VERSION_MAJOR) "." LIBDIVIDE_STR(LIBDIVIDE_VERSION_MINOR) "." LIBDIVIDE_STR(LIBDIVIDE_VERSION_PATCH))

#include <stdint.h>

Expand Down
1 change: 1 addition & 0 deletions test/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ extern "C" int main(int argc, char *argv[]) {
}
}

std::cout << "Testing libdivide v" << LIBDIVIDE_VERSION << std::endl;
std::string vecTypes = "";
#if defined(LIBDIVIDE_SSE2)
vecTypes += "sse2 ";
Expand Down