Skip to content

Commit

Permalink
Merge pull request #1 from Frederick888/setup-ci into master
Browse files Browse the repository at this point in the history
* setup-ci:
  ci: Add release Action
  chore: Add Justfile
  ci: Set up gh-ph
  ci: Set up test Actions
  • Loading branch information
Frederick888 committed Mar 23, 2023
2 parents b0a44d9 + 2d3bc92 commit d32ba99
Show file tree
Hide file tree
Showing 5 changed files with 254 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Description

# Changes
<!-- === GH HISTORY FORMAT FENCE === --> <!--
### [`%h`]({{.url}}/commits/%H) %s%n%n%b%n
--> <!-- === GH HISTORY FORMAT FENCE === -->
<!-- === GH HISTORY FENCE === -->
<!-- Do NOT write here! -->
<!-- It will be filled in by GitHub Actions automatically. -->
<!-- === GH HISTORY FENCE === -->

# Checklist

- [ ] I have rebased my branch so that it has no conflicts
- [ ] I have added tests where appropriate
- [ ] Commit messages are compliant with [Conventional Commits](https://www.conventionalcommits.org)

# Is this a breaking change?

<!-- Yes / No. Reason. -->
104 changes: 104 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI

on:
pull_request:
types:
- opened
- reopened
- synchronize
push:
branches:
- master

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Lint & Test
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
rust_toolchain: [stable]
experimental: [false]
include:
- rust_toolchain: nightly
experimental: true
steps:
- name: Cancel Previous Runs
if: contains(matrix.os, 'ubuntu')
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v3

- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust_toolchain }}
components: rustfmt, clippy
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-git-${{ github.sha }}
restore-keys: |
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
test-${{ runner.os }}-
- name: rustfmt
shell: bash
run: |
cargo fmt -- --check
- name: Clippy
shell: bash
run: |
cargo clippy --tests --examples --benches -- -D warnings
- name: Test
shell: bash
run: |
cargo test
doc:
name: Doc
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: doc-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-git-${{ github.sha }}
restore-keys: |
doc-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
doc-${{ runner.os }}-
- name: Render doc
shell: bash
run: |
cargo doc
- name: Artifacts
uses: actions/upload-artifact@v3
with:
name: doc
retention-days: 60
path: |
target/doc
16 changes: 16 additions & 0 deletions .github/workflows/gh-ph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull request history

on:
pull_request:

jobs:
gh-ph:
name: Add commit history to pull request description
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: Frederick888/gh-ph@v1
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82 changes: 82 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Release

on:
push:
tags:
- "v*"

env:
CARGO_TERM_COLOR: always

jobs:
create_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Conventional Commit Changelog
id: conventional_commits
run: |
curl -s -L -o./clog.tar.gz https://github.com/clog-tool/clog-cli/releases/download/v0.9.3/clog-v0.9.3-x86_64-unknown-linux-musl.tar.gz
tar -xf ./clog.tar.gz
chmod +x ./clog
# delete current tag locally
git tag -d "$GITHUB_REF_NAME"
if [[ "$GITHUB_REF_NAME" == *"-"* ]]; then
last_tag="$(git tag -l --sort version:refname | tail -n1)"
else
last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)"
fi
printf 'Using %s as last tag\n' "$last_tag"
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV
./clog --from="$last_tag" --setversion="$GITHUB_REF_NAME" >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Determine release type
id: release_type
shell: bash
run: |
[[ "$GITHUB_REF_NAME" == *"-"* ]] && is_pre='true' || is_pre='false'
printf 'is_pre=%s\n' "$is_pre" >> $GITHUB_OUTPUT
- name: Install Rust Toolchain
id: rust_toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-git-${{ github.sha }}
restore-keys: |
test-${{ runner.os }}-rustc-${{ steps.rust_toolchain.outputs.cachekey }}-
test-${{ runner.os }}-
- name: rustfmt
shell: bash
run: |
cargo fmt -- --check
- name: Clippy
shell: bash
run: |
cargo clippy --tests --examples --benches -- -D warnings
- name: Test
shell: bash
run: |
cargo test
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
draft: ${{ steps.release_type.outputs.is_pre }}
prerelease: ${{ steps.release_type.outputs.is_pre }}
body: ${{ env.CHANGELOG }}
token: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
set shell := ["bash", "+u", "-c"]

default:
cargo fmt -- --check
cargo clippy --examples --benches --tests
cargo test --quiet

lint:
cargo fmt -- --check
cargo clippy --examples --benches --tests -- -D warnings

release version:
set -e
@if [[ "{{version}}" == v* ]]; then printf 'Must not have v-prefix\n'; exit 1; fi
# changelog
if [[ "{{version}}" != *"-"* ]]; then \
last_tag="$(git tag -l --sort version:refname | grep -v -- - | tail -n1)"; \
clog --from="$last_tag" --setversion=v{{version}} -o ./CHANGELOG.md; \
git add ./CHANGELOG.md; \
fi
# host
sed 's/^version = ".*"$/version = "{{version}}"/' -i ./Cargo.toml
git add ./Cargo.toml
just lint
cargo test
# commit and tag
git status
git diff --exit-code
git commit -m 'chore: Bump version to {{version}}'
git tag v{{version}}

# vim: set filetype=just :

0 comments on commit d32ba99

Please sign in to comment.