From e9494d5f01c681561cba79441178f4b3838e74af Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Sun, 28 Apr 2024 23:48:06 +0200 Subject: [PATCH 1/3] new: use goreleaser for publishing --- .github/workflows/publish.yml | 56 +++++++++++++++++++++++++++-------- .goreleaser-hook.sh | 21 +++++++++++++ .goreleaser.yaml | 51 +++++++++++++++++++++++++++++++ Cargo.lock | 4 +-- Cargo.toml | 2 +- build/goreleaser/stub.go | 3 ++ 6 files changed, 122 insertions(+), 15 deletions(-) create mode 100755 .goreleaser-hook.sh create mode 100644 .goreleaser.yaml create mode 100644 build/goreleaser/stub.go diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 43b9bd77..992a82b9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,9 +6,9 @@ on: - 'v*.*.*' jobs: - publish: - name: Publish for ${{ matrix.name }} - runs-on: ${{ matrix.os }} + build: + name: Build for ${{ matrix.name }} + runs-on: ${{ matrix.runner }} env: CARGO: cargo @@ -26,14 +26,15 @@ jobs: - windows-x86 include: - name: linux-x86-gnu - os: ubuntu-latest + runner: ubuntu-latest family: linux arch: x86_64 target: x86_64-unknown-linux-gnu archiver: tar.gz asset: hl-linux-x86_64-gnu.tar.gz + skip: true - name: linux-x86-musl - os: ubuntu-latest + runner: ubuntu-latest family: linux arch: x86_64 target: x86_64-unknown-linux-musl @@ -41,15 +42,16 @@ jobs: asset: hl-linux-x86_64-musl.tar.gz cross: true - name: linux-arm-gnu - os: ubuntu-latest + runner: ubuntu-latest family: linux arch: aarch64 target: aarch64-unknown-linux-gnu archiver: tar.gz asset: hl-linux-arm64-gnu.tar.gz cross: true + skip: true - name: linux-arm-musl - os: ubuntu-latest + runner: ubuntu-latest family: linux arch: aarch64 target: aarch64-unknown-linux-musl @@ -57,21 +59,21 @@ jobs: asset: hl-linux-arm64-musl.tar.gz cross: true - name: macos-x86 - os: macos-latest + runner: macos-latest family: macos arch: x86_64 target: x86_64-apple-darwin archiver: tar.gz asset: hl-macos-x86_64.tar.gz - name: macos-arm - os: macos-latest + runner: macos-latest family: macos arch: aarch64 target: aarch64-apple-darwin archiver: tar.gz asset: hl-macos-arm64.tar.gz - name: macos-universal - os: macos-latest + runner: macos-latest family: macos arch: '{aarch64,x86_64}' target: '{aarch64,x86_64}-apple-darwin' @@ -79,7 +81,7 @@ jobs: asset: hl-macos.tar.gz universal: true - name: windows-x86 - os: windows-latest + runner: windows-latest family: windows arch: x86_64 target: x86_64-pc-windows-msvc @@ -87,7 +89,7 @@ jobs: asset: hl-windows.zip steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: @@ -128,9 +130,39 @@ jobs: if: matrix.archiver == 'tar.gz' && matrix.universal == true run: tar -C ./target -cz -f ${{ matrix.asset }} hl + - name: Store artifact + if: matrix.skip != true + uses: actions/upload-artifact@v4 + with: + name: hl-${{ matrix.arch }}-${{ matrix.family }} + path: target/${{ matrix.target }}/release/hl${{ matrix.family == 'windows' && '.exe' || '' }} + retention-days: 1 + - name: Upload binaries to release + if: startsWith(github.ref, 'refs/tags/v') uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: ${{ matrix.asset }} tag: ${{ github.ref }} + + publish: + name: Publish + needs: [build] + runs-on: ubuntu-22.04 + steps: + - name: Checkout Git repo + uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + path: artifacts + - name: Set up Go + uses: actions/setup-go@v5 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + args: release --clean --skip=validate + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser-hook.sh b/.goreleaser-hook.sh new file mode 100755 index 00000000..a6f152a3 --- /dev/null +++ b/.goreleaser-hook.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +go_arch=$1 +go_os=$2 +project_name=$3 + +# Make Go -> Rust arch/os mapping +case $go_arch in + amd64) rust_arch='x86_64' ;; + arm64) rust_arch='aarch64' ;; + *) echo "unknown arch: $go_arch" && exit 1 ;; +esac +case $go_os in + linux) rust_os='linux' ;; + darwin) rust_os='macos' ;; + windows) rust_os='windows' ;; + *) echo "unknown os: $go_os" && exit 1 ;; +esac + +# Find artifacts and uncompress in the corresponding directory +find artifacts -type f -name "${project_name}-${rust_arch}-${rust_os}" -exec mv {} dist/${project_name}_${go_os}_${go_arch} \; diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 00000000..aa989912 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +project_name: hl +builds: + - main: build/goreleaser/stub.go + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + binary: hl + ignore: + - goos: windows + goarch: arm64 + hooks: + post: + - ./.goreleaser-hook.sh {{ .Arch }} {{ .Os }} {{ .ProjectName }} +checksum: + name_template: "checksums.txt" +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" +brews: + - name: hl + repository: + owner: pamburus + name: homebrew-tap + branch: main + pull_request: + enabled: true + draft: true + url_template: "https://github.com/pamburus/hl/releases/download/{{ .Tag }}/{{ .ArtifactName }}" + commit_author: + name: Pavel Ivanov + email: mr.pavel.ivanov@gmail.com + commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}" + directory: Formula + homepage: "https://github.com/pamburus/hl" + description: "Log viewer for JSON and logfmt logs" + license: "MIT" + skip_upload: auto + custom_block: | + head "https://github.com/pamburus/hl.git" + test: | + system "#{bin}/hl --version" + install: | + system "cargo", "install", *std_cargo_args + generate_completions_from_executable(bin/"hl", "--shell-completions") diff --git a/Cargo.lock b/Cargo.lock index 1c38129a..819fdf90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -600,7 +600,7 @@ checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" [[package]] name = "encstr" -version = "0.28.0" +version = "0.28.1-beta.1" [[package]] name = "enum-map" @@ -757,7 +757,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hl" -version = "0.28.0" +version = "0.28.1-beta.1" dependencies = [ "atoi", "bincode", diff --git a/Cargo.toml b/Cargo.toml index ecc74222..7aafd78d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ members = [".", "crate/encstr"] [workspace.package] repository = "https://github.com/pamburus/hl" authors = ["Pavel Ivanov "] -version = "0.28.0" +version = "0.28.1-beta.1" edition = "2021" license = "MIT" diff --git a/build/goreleaser/stub.go b/build/goreleaser/stub.go new file mode 100644 index 00000000..38dd16da --- /dev/null +++ b/build/goreleaser/stub.go @@ -0,0 +1,3 @@ +package main + +func main() {} From 42d7f4ab5c8a333e971756fad478724372663e28 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Mon, 29 Apr 2024 00:45:53 +0200 Subject: [PATCH 2/3] tmp --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 992a82b9..d3f7cb6f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,6 +4,8 @@ on: push: tags: - 'v*.*.*' + pull_request: + branches: [master, release/*] jobs: build: From a18da489a662e5b6a103b95017fefd6a4d74b5e5 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Mon, 29 Apr 2024 11:30:06 +0200 Subject: [PATCH 3/3] tmp snapshot --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d3f7cb6f..281ea561 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -165,6 +165,6 @@ jobs: with: distribution: goreleaser version: latest - args: release --clean --skip=validate + args: release --clean --skip=validate --snapshot env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}