Skip to content

Commit

Permalink
feat: automate releases (#2)
Browse files Browse the repository at this point in the history
* copy release process from spec

* update changelog

* update Cargo.toml version when releasing

* build cli on release
  • Loading branch information
HectorCastelli authored Jan 9, 2024
1 parent 34a1ee2 commit dae910a
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 5 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Deploy
run-name: ${{ github.event_name == 'release' && github.ref_name || inputs.version }}

concurrency:
cancel-in-progress: false
group: '${{ github.workflow }}'

on:
release:
types:
- published
- edited
workflow_dispatch:
inputs:
version:
description: The version (the release name) to deploy
type: string
required: true

permissions:
contents: read

jobs:
setup:
name: Setup references
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.ref.outputs.ref }}
steps:
- name: Trigger on release
if: ${{ github.event_name == 'release' }}
run: echo "REF=${{ github.ref_name }}" >> "$GITHUB_ENV"
- name: Trigger on manual dispatch
if: ${{ github.event_name == 'workflow_dispatch' }}
run: echo "REF=${{ inputs.version }}" >> "$GITHUB_ENV"
- name: Set reference
id: ref
run: echo "ref=$REF" >> "$GITHUB_OUTPUT"
build:
name: Build
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v3
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install stable
rustup default stable
- name: Build cli
run: cargo build --release
- name: Attach to release
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
run: gh release upload ${{needs.setup.outputs.ref}} ./target/release/powerd6_tools --clobber
18 changes: 18 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ permissions:
contents: read

jobs:
markdown-lint:
name: Markdown lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: DavidAnson/markdownlint-cli2-action@v13
with:
globs: |
**/*.md
#**/.terraform/**/*.md
markdown-link-check:
name: Markdown Link Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
use-quiet-mode: yes
action-lint:
name: Action Lint
runs-on: ubuntu-latest
Expand Down
158 changes: 158 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Release
run-name: ${{inputs.release_type}}

concurrency:
cancel-in-progress: false
group: '${{ github.workflow }}'

on:
workflow_dispatch:
inputs:
release_type:
description: "Which type of release is this?"
type: choice
options:
- "patch"
- "minor"
- "major"
default: "patch"

permissions:
contents: write

jobs:
prepare:
name: Prepare release
runs-on: ubuntu-latest
outputs:
current: ${{ steps.current.outputs.version }}
next: ${{ steps.next.outputs.version }}
branch: ${{ steps.branch.outputs.branch }}
env:
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ADMIN_TOKEN }}
- name: Configure git
run: |-
gh api /user > user.json
git config --global user.email "$(jq -r '.email' user.json)"
git config --global user.name "$(jq -r '.name' user.json)"
- name: Prepare branch name
id: branch
run: echo "branch=release${{ github.run_id }}" >> "$GITHUB_OUTPUT"
- name: Create branch
run: git checkout -b "${{ steps.branch.outputs.branch }}"
- name: Install semver-cli
run: |-
go install github.com/maykonlf/semver-cli/cmd/semver@latest
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
- name: Get current version
id: current
run: echo "version=$(semver get release)" >> "$GITHUB_OUTPUT"
- name: Get next version
id: next
env:
FLAG: ${{ inputs.release_type == 'patch' && 'release' || inputs.release_type}}
run: |-
semver up "$FLAG"
echo "version=$(semver get release)" >> "$GITHUB_OUTPUT"
git add .semver.yaml
git commit -m "update .semver.yaml"
- name: Prepare environment variables
run: |-
{
echo "CURRENT=${{steps.current.outputs.version}}"
echo "NEXT=${{steps.next.outputs.version}}"
echo "CURRENT_CARGO=$(echo '${{ steps.current.outputs.version }}' | sed 's/v//')"
echo "NEXT_CARGO=$(echo '${{steps.next.outputs.version}}' | sed 's/v//')"
} >> "$GITHUB_ENV"
- name: update Cargo.toml
run: |-
sed -i "s/$CURRENT_CARGO/$NEXT_CARGO/g" Cargo.toml
git add Cargo.toml
git commit -m "update Cargo.toml"
- name: update CHANGELOG.md
run: |-
head -n 13 CHANGELOG.md > changelog.md.0
tail -n +15 CHANGELOG.md > changelog.md.1
# Reset the file
echo -n > CHANGELOG.md
{
cat changelog.md.0
echo "## [Unreleased](https://github.com/powerd6/spec/compare/$NEXT...HEAD)"
echo ""
echo "## [$NEXT](https://github.com/powerd6/spec/releases/tag/$NEXT)"
cat changelog.md.1
} >> CHANGELOG.md
rm changelog.md.*
git add CHANGELOG.md
git commit -m "update CHANGELOG.md"
- name: Push changes
run: git push -u origin "${{ steps.branch.outputs.branch }}"
pr:
name: Create Pull Request
runs-on: ubuntu-latest
needs:
- prepare
outputs:
pr: ${{ steps.pr.outputs.link }}
env:
NEXT: ${{needs.prepare.outputs.next}}
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{needs.prepare.outputs.branch}}
- name: Create Pull Request
id: pr
run: |-
PR_URL=$(gh pr create --title "chore: prepare release for $NEXT" --body "")
echo "link=$PR_URL" >> "$GITHUB_OUTPUT"
- name: Document
run: |-
echo "[PR link](${{ steps.pr.outputs.link }})" >> "$GITHUB_STEP_SUMMARY"
merge:
name: Merge Pull Request
runs-on: ubuntu-latest
needs: pr
env:
PR_URL: ${{needs.pr.outputs.pr}}
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Merge PR
run: gh pr merge "$PR_URL" --admin --squash
draft:
name: Draft release
runs-on: ubuntu-latest
needs:
- prepare
- merge
outputs:
release: ${{ steps.release.outputs.link }}
env:
NEXT: ${{needs.prepare.outputs.next}}
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Create Release
id: release
run: |-
RELEASE_URL=$(gh release create "$NEXT" \
--target main \
--title "$NEXT" \
--generate-notes \
--latest \
--draft)
echo "link=$RELEASE_URL" >> "$GITHUB_OUTPUT"
- name: Document
run: |-
echo "[Release link](${{ steps.release.outputs.link }})" >> "$GITHUB_STEP_SUMMARY"
4 changes: 4 additions & 0 deletions .semver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alpha: 0
beta: 0
rc: 0
release: v0.0.0
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"streetsidesoftware.code-spell-checker",
"rust-lang.rust-analyzer",
"redhat.vscode-yaml"
"redhat.vscode-yaml",
"tamasfe.even-better-toml"
]
}
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ 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).

<!-- markdown-link-check-disable -->
## [Unreleased](https://github.com/powerd6/spec/compare/51beac5...HEAD)
## [Unreleased](https://github.com/powerd6/tools/compare/v0.0.0...HEAD)

### Added

- Create new cli
- Add `initialize` command to bootstrap new projects
- Automate release process

## [v0.0.0](https://github.com/powerd6/tools/releases/tag/v0.0.0)

### Added

- Initialized the repository
<!-- markdown-link-check-enable -->
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[package]
name = "powerd6_tools"
version = "0.1.0"
description = "A collection of tools to work with powerd6 artifacts."
version = "0.0.1"
edition = "2021"
readme = "README.md"
homepage = ""
repository = "https://github.com/powerd6/tools/"
keywords = ["powerd6", "ttrpg"]
categories = ["command-line-utilities"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# powerd6/tools

A collection of tools to work with powerd6 artifacts.
A collection of tools to work with powerd6 artifacts.

0 comments on commit dae910a

Please sign in to comment.