Skip to content

Commit

Permalink
chore: automate releases
Browse files Browse the repository at this point in the history
  • Loading branch information
pepicrft committed Aug 11, 2024
1 parent fdac1c8 commit 34728b1
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 1 deletion.
18 changes: 18 additions & 0 deletions .github/workflows/conventional-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: conventional-pr
on:
pull_request:
branches:
- main
- master
types:
- opened
- edited
- synchronize
jobs:
lint-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: CondeNast/conventional-pull-request-action@v0.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
90 changes: 90 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Release

on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'The version to release'
type: string

permissions:
contents: write
pull-requests: read
statuses: write
packages: write

jobs:
release:
name: Release
runs-on: 'ubuntu-latest'
timeout-minutes: 15
if: "!startsWith(github.event.head_commit.message, '[Release]')"
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
fetch-depth: 0
- uses: jdx/mise-action@v2
with:
experimental: true
- name: Check if there are releasable changes
id: is-releasable
run: |
# Run git cliff and save the output
bumped_output=$(git cliff --bump)
echo "Bumped output:"
echo "${bumped_output}"
# Read the content of CHANGELOG.md
changelog_content=$(cat CHANGELOG.md)
echo "CHANGELOG.md content:"
echo "${changelog_content}"
# Compare the outputs and set the result
if [ "${bumped_output}" = "${changelog_content}" ]; then
echo "should-release=false" >> $GITHUB_ENV
else
echo "should-release=true" >> $GITHUB_ENV
fi
- name: Get next version
id: next-version
if: env.should-release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: echo "NEXT_VERSION=$(git cliff --bumped-version)" >> "$GITHUB_OUTPUT"
- name: Get release notes
id: release-notes
if: env.should-release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "RELEASE_NOTES<<EOF" >> "$GITHUB_OUTPUT"
git cliff --unreleased >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Update CHANGELOG.md
if: env.should-release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: git cliff --bump -o CHANGELOG.md
- name: Commit changes
id: auto-commit-action
uses: stefanzweifel/git-auto-commit-action@v5
if: env.should-release == 'true'
with:
commit_options: '--allow-empty'
tagging_message: ${{ steps.next-version.outputs.NEXT_VERSION }}
skip_dirty_check: true
commit_message: "[Release] Path ${{ steps.next-version.outputs.NEXT_VERSION }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
if: env.should-release == 'true'
with:
draft: false
repository: tuist/Path
name: ${{ steps.next-version.outputs.NEXT_VERSION }}
tag_name: ${{ steps.next-version.outputs.NEXT_VERSION }}
body: ${{ steps.release-notes.outputs.RELEASE_NOTES }}
target_commitish: ${{ steps.auto-commit-action.outputs.commit_hash }}
3 changes: 2 additions & 1 deletion .mise.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tools]
"tuist" = "4.23.0"
"swiftlint" = "0.54.0"
"swiftformat" = "0.52.10"
"swiftformat" = "0.52.10"
"git-cliff" = "2.4.0"
109 changes: 109 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# git-cliff ~ configuration file
# https://git-cliff.org/docs/configuration

[remote.github]
owner = "tuist"
repo = "XcodeProj"
# token = ""

[changelog]
# template for the changelog header
header = """
# Changelog\n
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{% if version -%}
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else -%}
## [Unreleased]
{% endif -%}
### Details\
{% for group, commits in commits | group_by(attribute="group") %}
#### {{ group | upper_first }}
{%- for commit in commits %}
- {{ commit.message | upper_first | trim }}\
{% if commit.github.username %} by @{{ commit.github.username }}{%- endif -%}
{% if commit.github.pr_number %} in \
[#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }}) \
{%- endif -%}
{% endfor %}
{% endfor %}
{%- if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
## New Contributors
{%- endif -%}
{% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
* @{{ contributor.username }} made their first contribution
{%- if contributor.pr_number %} in \
[#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
{%- endif %}
{%- endfor %}\n
"""
# template for the changelog footer
footer = """
{%- macro remote_url() -%}
https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
{%- endmacro -%}
{% for release in releases -%}
{% if release.version -%}
{% if release.previous.version -%}
[{{ release.version | trim_start_matches(pat="v") }}]: \
{{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }}
{% endif -%}
{% else -%}
[unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD
{% endif -%}
{% endfor %}
<!-- generated by git-cliff -->
"""
# remove the leading and trailing whitespace from the templates
trim = true
# postprocessors
postprocessors = []

[git]
# parse the commits based on https://www.conventionalcommits.org
conventional_commits = true
# filter out the commits that are not conventional
filter_unconventional = true
# process each line of a commit as an individual commit
split_commits = false
# regex for preprocessing the commit messages
commit_preprocessors = [
# remove issue numbers from commits
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
]
# protect breaking changes from being skipped due to matching a skipping commit_parser
protect_breaking_commits = false
# filter out the commits that are not matched by commit parsers
filter_commits = false
# regex for matching git tags
tag_pattern = "[0-9].*"
# regex for skipping tags
skip_tags = "beta|alpha"
# regex for ignoring tags
ignore_tags = "rc"
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "newest"

[bump]
breaking_always_bump_major = true
features_always_bump_minor=true
initial_tag="8.22.0"

0 comments on commit 34728b1

Please sign in to comment.