From 7350f995775035f7930d5be9e3e168b93fe4cc66 Mon Sep 17 00:00:00 2001 From: Steven Kessler Date: Tue, 1 Oct 2024 16:03:03 -0400 Subject: [PATCH 1/3] wip(releasing via goreleaser): --- .github/workflows/release.yaml | 132 ++++++++++++++++++++++++++------- .gitignore | 3 +- .goreleaser.sh | 21 ++++++ .goreleaser.yaml | 25 +++++++ goreleaser.go | 4 + 5 files changed, 156 insertions(+), 29 deletions(-) create mode 100644 .goreleaser.sh create mode 100644 .goreleaser.yaml create mode 100644 goreleaser.go diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9847ae9..97e8b1a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,46 +1,122 @@ on: + # Indicates I want to run this workflow on all branches, PR, and tags push: - tags: [ 'v*.*.*' ] + branches: ["**"] + tags: ["*"] + pull_request: + branches: [ "main" ] + +env: + # Define the rust version to use + RUST_VERSION: 1.81.1 + # Rust build arguments + BUILD_ARGS: "--release --all-features" + # The binary name + BIN_NAME: "uv-migrator" + # Docker token required to pull images from DockerHub + DOCKER_LOGIN: ${{ secrets.DOCKER_LOGIN }} + DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} jobs: - release: - name: Release - ${{ matrix.platform.target }} + build: + name: Build - ${{ matrix.platform.name }} + # By default, runs on Ubuntu, otherwise, override with the desired os + runs-on: ${{ matrix.platform.os || 'ubuntu-22.04' }} strategy: matrix: + # Set platforms you want to build your binaries on platform: - - os_name: Windows-x86_64 - os: windows-latest - target: x86_64-pc-windows-msvc - - - os_name: Linux-x86_64 - os: ubuntu-20.04 - target: x86_64-unknown-linux-musl + # Linux + # The name is used for pretty print + - name: Linux x86_64 + # The used Rust target architecture + target: x86_64-unknown-linux-gnu + - name: Linux aarch64 + target: aarch64-unknown-linux-gnu - - os_name: macOS-x86_64 - os: macOS-latest + # Mac OS + - name: MacOS x86_64 target: x86_64-apple-darwin - - - os_name: macOS-aarch64 - os: macOS-latest + - name: MacOS aarch64 target: aarch64-apple-darwin - runs-on: ${{ matrix.platform.os }} + # Windows + - name: Windows x86_64 + # Use another GitHub action OS + os: windows-latest + target: x86_64-pc-windows-msvc + steps: - - name: Checkout + - name: Checkout Git repo uses: actions/checkout@v4 - - name: Build binary - uses: houseabsolute/actions-rust-cross@v0 + # Linux & Windows + - name: Install rust toolchain + if: ${{ !contains(matrix.platform.target, 'apple') }} + uses: actions-rs/toolchain@v1 with: - command: ${{ matrix.platform.command }} + # We setup Rust toolchain and the desired target + profile: minimal + toolchain: "${{ env.RUST_VERSION }}" + override: true target: ${{ matrix.platform.target }} - args: "--locked --release" - strip: true + components: rustfmt, clippy + - name: Build ${{ matrix.platform.name }} binary + if: ${{ !contains(matrix.platform.target, 'apple') }} + uses: actions-rs/cargo@v1 + # We use cross-rs if not running on x86_64 architecture on Linux + with: + command: build + use-cross: ${{ !contains(matrix.platform.target, 'x86_64') }} + args: ${{ env.BUILD_ARGS }} --target ${{ matrix.platform.target }} - - name: Publish artifacts and release - uses: houseabsolute/actions-rust-release@v0 + # Mac OS + - name: Login to DockerHub + if: contains(matrix.platform.target, 'apple') + # We log on DockerHub + uses: docker/login-action@v3 with: - changes-file: "" - archive-name: "uv-migrator - ${{ matrix.platform.target }}" - target: ${{ matrix.platform.target }} - executable-name: 'uv-migrator' + username: ${{ env.DOCKER_LOGIN }} + password: ${{ env.DOCKER_TOKEN }} + - name: Build ${{ matrix.platform.name }} binary + if: contains(matrix.platform.target, 'apple') + # We use a dedicated Rust image containing required Apple libraries to cross-compile on multiple archs + run: | + docker run --rm --volume "${PWD}":/root/src --workdir /root/src joseluisq/rust-linux-darwin-builder:$RUST_VERSION \ + sh -c "CC=o64-clang CXX=o64-clang++ cargo build $BUILD_ARGS --target ${{ matrix.platform.target }}" + + - name: Store artifact + uses: actions/upload-artifact@v4 + with: + # Finally, we store the binary as GitHub artifact for later usage + name: ${{ matrix.platform.target }}-${{ env.BIN_NAME }} + path: target/${{ matrix.platform.target }}/release/${{ env.BIN_NAME }}${{ contains(matrix.platform.target, 'windows') && '.exe' || '' }} + retention-days: 1 + + release: + name: Release + needs: [build] + # We run the release job only if a tag starts with 'v' letter + if: startsWith( github.ref, 'refs/tags/v' ) + runs-on: ubuntu-22.04 + steps: + - name: Checkout Git repo + uses: actions/checkout@v3 + + # Download all artifacts + - uses: actions/download-artifact@v3 + with: + path: artifacts + + # Goreleaser + - name: Set up Go + uses: actions/setup-go@v4 + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + distribution: goreleaser + version: latest + # Run goreleaser and ignore non-committed files (downloaded artifacts) + args: release --clean --skip=validate + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN_RUST_CROSS }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2674b3d..9777cdb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .idea -.vscode \ No newline at end of file +.vscode +dist/ diff --git a/.goreleaser.sh b/.goreleaser.sh new file mode 100644 index 0000000..9d0c999 --- /dev/null +++ b/.goreleaser.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='apple-darwin' ;; + 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 "*${rust_arch}*${rust_os}*" -exec unzip -d dist/${project_name}_${go_os}_${go_arch} {} \; \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..e5ebfa7 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,25 @@ +project_name: example +builds: + - main: goreleaser.go + goos: + - linux + - darwin + - windows + goarch: + - amd64 + - arm64 + binary: uv-migrator + 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:" \ No newline at end of file diff --git a/goreleaser.go b/goreleaser.go new file mode 100644 index 0000000..da29a2c --- /dev/null +++ b/goreleaser.go @@ -0,0 +1,4 @@ +package main + +func main() { +} From 04e6132ad0e3532188b7c56aaec5f46528a06382 Mon Sep 17 00:00:00 2001 From: Steven Kessler Date: Tue, 1 Oct 2024 16:05:48 -0400 Subject: [PATCH 2/3] wip(releasing via goreleaser): --- .github/workflows/release.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 97e8b1a..8114537 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,8 +1,8 @@ on: # Indicates I want to run this workflow on all branches, PR, and tags push: - branches: ["**"] - tags: ["*"] + branches: [ "**" ] + tags: [ "*" ] pull_request: branches: [ "main" ] @@ -95,7 +95,7 @@ jobs: release: name: Release - needs: [build] + needs: [ build ] # We run the release job only if a tag starts with 'v' letter if: startsWith( github.ref, 'refs/tags/v' ) runs-on: ubuntu-22.04 @@ -110,9 +110,9 @@ jobs: # Goreleaser - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: distribution: goreleaser version: latest From 90532720bbd8d84cbe892779d93cc71fa8b78062 Mon Sep 17 00:00:00 2001 From: Steven Kessler Date: Tue, 1 Oct 2024 16:06:50 -0400 Subject: [PATCH 3/3] wip(releasing via goreleaser): --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 8114537..d903539 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -8,7 +8,7 @@ on: env: # Define the rust version to use - RUST_VERSION: 1.81.1 + RUST_VERSION: 1.72.1 # Rust build arguments BUILD_ARGS: "--release --all-features" # The binary name