diff --git a/.github/workflows/build-and-lint.yml b/.github/workflows/build-and-lint.yml new file mode 100644 index 0000000..194c6fa --- /dev/null +++ b/.github/workflows/build-and-lint.yml @@ -0,0 +1,33 @@ +name: Build and Lint + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: Build + run: go build -v ./... + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0d1c30b..821b7cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,28 +1,77 @@ -name: release +name: Release on: push: tags: - - "v*" + - 'v*' + +permissions: + contents: write jobs: - release: - runs-on: ubuntu-latest - permissions: - contents: write + build: + strategy: + matrix: + include: + - target: darwin-amd64 + os: macos-latest + goos: darwin + goarch: amd64 + name: draw-x86_64-apple-darwin + - target: darwin-arm64 + os: macos-latest + goos: darwin + goarch: arm64 + name: draw-aarch64-apple-darwin + - target: linux-amd64 + os: ubuntu-latest + goos: linux + goarch: amd64 + name: draw-x86_64-unknown-linux-gnu + + runs-on: ${{ matrix.os }} + steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: actions/setup-go@v5 + - name: Setup Go + uses: actions/setup-go@v5 with: go-version-file: go.mod cache: true - - uses: goreleaser/goreleaser-action@v6 + - name: Build + run: | + CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o draw . + + - name: Package + run: | + mkdir -p dist + cp draw dist/ + cd dist + tar -czvf ${{ matrix.name }}.tar.gz draw + shasum -a 256 ${{ matrix.name }}.tar.gz > ${{ matrix.name }}.tar.gz.sha256 + + - name: Upload artifact + uses: actions/upload-artifact@v4 with: - args: release --rm-dist + name: ${{ matrix.name }} + path: dist/${{ matrix.name }}.tar.gz* + + release: + needs: build + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Download artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + merge-multiple: true + + - name: Create Release and Upload Assets + run: gh release create ${{ github.ref_name }} artifacts/* --generate-notes env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index c6305b2..0863ff7 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ dist/ .DS_Store + +/Formula diff --git a/.goreleaser.yaml b/.goreleaser.yaml deleted file mode 100644 index b22ae0f..0000000 --- a/.goreleaser.yaml +++ /dev/null @@ -1,51 +0,0 @@ -# This is an example .goreleaser.yml file with some sensible defaults. -# Make sure to check the documentation at https://goreleaser.com -before: - hooks: - # You may remove this if you don't use go modules. - - go mod tidy - # you may remove this if you don't need go generate - - go generate ./... -builds: - - env: - - CGO_ENABLED=0 - goos: - - linux - - windows - - darwin - -archives: - - format: tar.gz - # this name template makes the OS and Arch compatible with the results of uname. - name_template: >- - {{ .ProjectName }}_ - {{- title .Os }}_ - {{- if eq .Arch "amd64" }}x86_64 - {{- else if eq .Arch "386" }}i386 - {{- else }}{{ .Arch }}{{ end }} - {{- if .Arm }}v{{ .Arm }}{{ end }} - # use zip for windows archives - format_overrides: - - goos: windows - format: zip -checksum: - name_template: 'checksums.txt' -snapshot: - name_template: "{{ incpatch .Version }}-next" -changelog: - sort: asc - filters: - exclude: - - '^docs:' - - '^test:' - -# The lines beneath this are called `modelines`. See `:help modeline` -# Feel free to remove those if you don't want/use them. -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# vim: set ts=2 sw=2 tw=0 fo=cnqoj - -brews: - - tap: - owner: Doarakko - name: homebrew-tap - token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}" \ No newline at end of file diff --git a/scripts/update-homebrew.sh b/scripts/update-homebrew.sh new file mode 100755 index 0000000..50b8d28 --- /dev/null +++ b/scripts/update-homebrew.sh @@ -0,0 +1,79 @@ +#!/bin/bash +set -e + +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "Example: $0 0.1.3" + exit 1 +fi + +VERSION=$1 +REPO="Doarakko/draw" +TMP_DIR=$(mktemp -d) + +echo "Downloading release assets for v${VERSION}..." +gh release download "v${VERSION}" --repo "$REPO" --pattern "*.tar.gz" --dir "$TMP_DIR" + +echo "" +echo "Calculating sha256..." +X86_64_DARWIN=$(shasum -a 256 "$TMP_DIR/draw-x86_64-apple-darwin.tar.gz" | awk '{print $1}') +AARCH64_DARWIN=$(shasum -a 256 "$TMP_DIR/draw-aarch64-apple-darwin.tar.gz" | awk '{print $1}') +X86_64_LINUX=$(shasum -a 256 "$TMP_DIR/draw-x86_64-unknown-linux-gnu.tar.gz" | awk '{print $1}') + +echo "x86_64-apple-darwin: $X86_64_DARWIN" +echo "aarch64-apple-darwin: $AARCH64_DARWIN" +echo "x86_64-unknown-linux-gnu: $X86_64_LINUX" + +echo "" +echo "Generating formula..." + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +OUTPUT_FILE="$SCRIPT_DIR/../Formula/draw.rb" +mkdir -p "$(dirname "$OUTPUT_FILE")" + +cat > "$OUTPUT_FILE" << EOF +class Draw < Formula + desc "Display Yu-Gi-Oh! card image on the terminal" + homepage "https://github.com/Doarakko/draw" + version "${VERSION}" + license "MIT" + + on_macos do + on_intel do + url "https://github.com/Doarakko/draw/releases/download/v#{version}/draw-x86_64-apple-darwin.tar.gz" + sha256 "${X86_64_DARWIN}" + end + + on_arm do + url "https://github.com/Doarakko/draw/releases/download/v#{version}/draw-aarch64-apple-darwin.tar.gz" + sha256 "${AARCH64_DARWIN}" + end + end + + on_linux do + on_intel do + url "https://github.com/Doarakko/draw/releases/download/v#{version}/draw-x86_64-unknown-linux-gnu.tar.gz" + sha256 "${X86_64_LINUX}" + end + end + + def install + bin.install "draw" + end + + test do + assert_match "draw", shell_output("#{bin}/draw --help", 2) + end +end +EOF + +echo "" +echo "Generated: $OUTPUT_FILE" +cat "$OUTPUT_FILE" + +echo "" +echo "Cleaning up..." +rm -rf "$TMP_DIR" + +echo "" +echo "Done! Copy Formula/draw.rb to homebrew-tap/Formula/draw.rb"