Skip to content

Commit

Permalink
chore: add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nothinux committed Aug 27, 2023
1 parent 60f6dcf commit 0d60300
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/release-notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3

import argparse
import re
import pathlib
import sys


_STDIO = pathlib.Path("-")


def main():
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", type=pathlib.Path, default="CHANGELOG.md")
parser.add_argument("--tag", required=True)
parser.add_argument("-o", "--output", type=pathlib.Path, required=True)
args = parser.parse_args()

if args.input == _STDIO:
lines = sys.stdin.readlines()
else:
with args.input.open() as fh:
lines = fh.readlines()
version = args.tag.lstrip("v")

note_lines = []
for line in lines:
if line.startswith("## ") and version in line:
note_lines.append(line)
elif note_lines and line.startswith("## "):
break
elif note_lines:
note_lines.append(line)

notes = "".join(note_lines).strip()
if args.output == _STDIO:
print(notes)
else:
args.output.write_text(notes)


if __name__ == "__main__":
main()
91 changes: 91 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: release
permissions:
contents: write
on:
push:
tags:
- "v*.*.*"
env:
BIN_NAME: kubectl-resource_status
jobs:
create-release:
name: create-release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
release_version: ${{ github.ref_name }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Generate Release Notes
run: |
./.github/workflows/release-notes.py --tag ${{ github.ref_name }} --output notes-${{ github.ref_name }}.md
cat notes-${{ github.ref_name }}.md
- name: Create GitHub release
id: release
uses: softprops/action-gh-release@v1
with:
body_path: notes-${{ github.ref_name }}.md
build-release:
name: build-release
needs: create-release
strategy:
matrix:
build: [x86_64-apple-darwin, aarch64-apple-darwin]
include:
- build: x86_64-apple-darwin
os: macos-latest
rust: stable
target: x86_64-apple-darwin
- build: aarch64-apple-darwin
os: macos-latest
rust: stable
target: aarch64-apple-darwin
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Build release binary
run: cargo build --target ${{ matrix.target }} --release
- name: Build archive
shell: bash
run: |
bin_dir="${{ env.BIN_NAME }}-${{ needs.create-release.outputs.release_version }}-${{ matrix.target }}"
cp "target/${{ matrix.target }}/release/${{ env.BIN_NAME }}" "$bin_dir/"
tar czf "$bin_dir.tar.gz" -C "$bin_dir" .
echo "ASSET=$bin_dir.tar.gz" >> $GITHUB_ENV
- name: Upload release archive
uses: softprops/action-gh-release@v1
with:
files: |
${{ env.ASSET }}
homebrew-releaser:
runs-on: ubuntu-latest
needs: build-release
name: homebrew-releaser
steps:
- name: Release to Homebrew tap
uses: Justintime50/homebrew-releaser@v1
with:
homebrew_owner: nothinux
homebrew_tap: homebrew-tools
formula_folder: formula
github_token: ${{ secrets.TAP_TOKEN }}
install: 'bin.install "kubectl-resource_status"'
target_darwin_amd64: true
target_darwin_arm64: true
target_linux_amd64: true
target_linux_arm64: false
update_readme_table: true
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Test
on:
push:
paths:
- "src/**.rs"
pull_request:
paths:
- "src/**.rs"

jobs:
test:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 0d60300

Please sign in to comment.