Skip to content

Commit

Permalink
chore(cd): add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
petit-chat committed Aug 19, 2024
1 parent 33e6d54 commit 973677d
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 30 deletions.
147 changes: 147 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Continuous Deployment

on:
workflow_dispatch:

jobs:
prepare-release:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-bumped-version.outputs.version }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set Up git-cliff
uses: kenji-miyake/setup-git-cliff@v2

- name: Get Bumped Version
id: get-bumped-version
run: |
TAG=$(git cliff --bumped-version)
echo "VERSION=${TAG#v}" >> "$GITHUB_OUTPUT"
- name: Generate Changelog
run: |
git cliff --bump --output CHANGELOG.md --no-exec --github-repo ${{ github.repository }}
- name: Update Version
env:
VERSION: ${{ steps.get-bumped-version.outputs.VERSION }}
run: |
sed -E -i "s/^version = \"[0-9\.]+\"$/version = \"${{ env.VERSION }}\"/" Cargo.toml
sed -E -i "s/^[0-9\.]+$/${{ env.VERSION }}/" README.md
- name: Commit Changes
env:
VERSION: ${{ steps.get-bumped-version.outputs.VERSION }}
run: |
git config --local user.email "[email protected]"
git config --local user.name "actions[bot]"
git add Cargo.toml CHANGELOG.md README.md
git commit -m "chore(release): v${{ env.VERSION }}"
git push
- name: Generate Release Notes
run: |
git cliff --bump --unreleased --output RELEASE_NOTES.md --no-exec --github-repo ${{ github.repository }}
- name: Create Draft Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ steps.get-bumped-version.outputs.VERSION }}
run: |
gh release create v${{ env.VERSION }} --draft --notes-file RELEASE_NOTES.md
build-and-upload-assets:
name: Build and Upload Assets
needs: prepare-release
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
ASSET_NAME: petit-filou-${{ needs.prepare-release.outputs.version }}-${{ matrix.rustc-target }}
VERSION: ${{ needs.prepare-release.outputs.version }}
permissions:
contents: write
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
rustc-target: x86_64-unknown-linux-gnu
- os: windows-latest
rustc-target: x86_64-pc-windows-gnu
- os: windows-latest
rustc-target: x86_64-pc-windows-msvc
- os: windows-latest
rustc-target: i686-pc-windows-msvc
- os: windows-latest
rustc-target: aarch64-pc-windows-msvc
- os: macos-latest
rustc-target: x86_64-apple-darwin
- os: macos-latest
rustc-target: aarch64-apple-darwin
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
target: ${{ matrix.rustc-target }}

- name: Compile petit-filou
run: |
cargo build --verbose --release --locked --target ${{ matrix.rustc-target }}
- name: Prepare Release Assets
shell: bash
run: |
mkdir -p r/{complete,doc}
cp {README.md,LICENSE} r/
cp CHANGELOG.md r/doc/
OUT_DIR=r/complete/ cargo run --bin generate-complete --locked --release
OUT_DIR=r/doc/ cargo run --bin generate-man --locked --release
mv r ${{ env.ASSET_NAME }}
- name: Archive and Upload Assets (Windows)
if: matrix.os == 'windows-latest'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
cp target/${{ matrix.rustc-target }}/release/{petit-filou.exe,generate-complete.exe,generate-man.exe} ${{ env.ASSET_NAME }}
7z a ${{ env.ASSET_NAME }}.zip ${{ env.ASSET_NAME }}
certutil -hashfile ${{ env.ASSET_NAME }}.zip SHA256 > ${{ env.ASSET_NAME }}.zip.sha256
gh release upload v${{ env.VERSION }} ${{ env.ASSET_NAME }}.zip#${{ matrix.rustc-target }} ${{ env.ASSET_NAME }}.zip.sha256#${{ matrix.rustc-target }}.sha256
- name: Archive and Upload Assets (Unix)
if: matrix.os != 'windows-latest'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cp target/${{ matrix.rustc-target }}/release/{petit-filou,generate-complete,generate-man} ${{ env.ASSET_NAME }}
tar czf ${{ env.ASSET_NAME }}.tar.gz ${{ env.ASSET_NAME }}
shasum -a 256 ${{ env.ASSET_NAME }}.tar.gz > ${{ env.ASSET_NAME }}.tar.gz.sha256
gh release upload v${{ env.VERSION }} ${{ env.ASSET_NAME }}.tar.gz#${{ matrix.rustc-target }} ${{ env.ASSET_NAME }}.tar.gz.sha256#${{ matrix.rustc-target }}.sha256
publish-release:
name: Publish Release
needs: [prepare-release, build-and-upload-assets]
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Publish Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release edit v${{ needs.prepare-release.outputs.version }} --draft=false
30 changes: 0 additions & 30 deletions .github/workflows/release.yml

This file was deleted.

88 changes: 88 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# git-cliff ~ default configuration file
# https://git-cliff.org/docs/configuration
#
# Lines starting with "#" are comments.
# Configuration options are organized into tables and keys.
# See documentation for more information on available options.

[changelog]
# template for the changelog footer
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
This file is generated by [git-cliff](https://git-cliff.org) based on commit messages.\n
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/); this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Conventional Commit](https://www.conventionalcommits.org/).\n
"""
# template for the changelog body
# https://keats.github.io/tera/docs/#introduction
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim | upper_first }}
{% for commit in commits %}
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
{% if commit.breaking %}[**breaking**] {% endif %}\
{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing s
trim = true
# postprocessors
postprocessors = [
# { pattern = '<REPO>', replace = "https://github.com/orhun/git-cliff" }, # replace repository URL
]

[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 = [
# Replace issue numbers
#{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](<REPO>/issues/${2}))"},
# Check spelling of the commit with https://github.com/crate-ci/typos
# If the spelling is incorrect, it will be automatically fixed.
#{ pattern = '.*', replace_command = 'typos --write-changes -' },
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = "^feat", group = "<!-- 0 -->🚀 Features" },
{ message = "^fix", group = "<!-- 1 -->🐛 Bug Fixes" },
{ message = "^doc", group = "<!-- 3 -->📚 Documentation" },
{ message = "^perf", group = "<!-- 4 -->⚡ Performance" },
{ message = "^refactor", group = "<!-- 2 -->🚜 Refactor" },
{ message = "^style", group = "<!-- 5 -->🎨 Styling" },
{ message = "^test", group = "<!-- 6 -->🧪 Testing" },
{ message = "^chore\\(release\\)", skip = true },
{ message = "^chore|^ci", group = "<!-- 7 -->⚙️ Miscellaneous Tasks" },
{ body = ".*security", group = "<!-- 8 -->🛡️ Security" },
{ message = "^revert", group = "<!-- 9 -->◀️ Revert" },
]
# 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 = "v[0-9].*"
# regex for skipping tags
# skip_tags = ""
# regex for ignoring tags
# ignore_tags = ""
# sort the tags topologically
topo_order = false
# sort the commits inside sections by oldest/newest order
sort_commits = "oldest"
# limit the number of commits included in the changelog.
# limit_commits = 42

0 comments on commit 973677d

Please sign in to comment.