diff --git a/.github/workflows/release-notes.py b/.github/workflows/release-notes.py new file mode 100755 index 0000000..1da029b --- /dev/null +++ b/.github/workflows/release-notes.py @@ -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() \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e1cd433 --- /dev/null +++ b/.github/workflows/release.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c3e9f97..60fca21 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,11 @@ name: Test on: push: + paths: + - "src/**.rs" pull_request: + paths: + - "src/**.rs" jobs: test: diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +