From a338fe297143965503b3cbaade7e147d5ab1981c Mon Sep 17 00:00:00 2001 From: Andrey Valynko Date: Mon, 22 Jan 2024 16:15:41 +0100 Subject: [PATCH] feat: move to releaser --- .github/builder/Dockerfile | 19 --------- .github/builder/README.MD | 60 --------------------------- .github/builder/entrypoint.sh | 77 ----------------------------------- .github/workflows/main.yaml | 47 ++++++++++----------- .goreleaser.yaml | 52 +++++++++++++++++++++++ 5 files changed, 76 insertions(+), 179 deletions(-) delete mode 100644 .github/builder/Dockerfile delete mode 100644 .github/builder/README.MD delete mode 100755 .github/builder/entrypoint.sh create mode 100644 .goreleaser.yaml diff --git a/.github/builder/Dockerfile b/.github/builder/Dockerfile deleted file mode 100644 index 691ebf0..0000000 --- a/.github/builder/Dockerfile +++ /dev/null @@ -1,19 +0,0 @@ -FROM golang:1.12 - -LABEL "name"="Go Builder" -LABEL "version"="0.2.0" - -LABEL "com.github.actions.name"="Go Builder" -LABEL "com.github.actions.description"="Cross-complile Go programs" -LABEL "com.github.actions.icon"="package" -LABEL "com.github.actions.color"="#E0EBF5" - -RUN \ - apt-get update && \ - apt-get install -y ca-certificates openssl zip && \ - update-ca-certificates && \ - rm -rf /var/lib/apt - -COPY entrypoint.sh /entrypoint.sh - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/builder/README.MD b/.github/builder/README.MD deleted file mode 100644 index f16ffa2..0000000 --- a/.github/builder/README.MD +++ /dev/null @@ -1,60 +0,0 @@ -# Go Builder - -This action is adapted from https://github.com/sosedoff/actions/tree/master/golang-build - -Github Action to cross-compile Go project binaries for multiple platforms in a single run. - -Uses `golang:1.12` Docker image with `CGO_ENABLED=0` flag. - -## Usage - -Basic usage: - -``` -action "build" { - uses = "./actions/build" -} -``` - -Basic workflow configuration will compile binaries for the following platforms: - -- linux: 386/amd64 -- darwin: 386/amd64/arm64 -- windows: 386/amd64 - -Alternatively you can provide a list of target architectures in `arg`: - -``` -action "build" { - uses = "./actions/build" - args = "linux/amd64 darwin/amd64" -} -``` - -Example output: - -``` -----> Setting up Go repository -----> Building project for: darwin/amd64 - adding: test-go-action_darwin_amd64 (deflated 50%) -----> Building project for: darwin/386 - adding: test-go-action_darwin_386 (deflated 45%) -----> Building project for: linux/amd64 - adding: test-go-action_linux_amd64 (deflated 50%) -----> Building project for: linux/386 - adding: test-go-action_linux_386 (deflated 45%) -----> Building project for: windows/amd64 - adding: test-go-action_windows_amd64 (deflated 50%) -----> Building project for: windows/386 - adding: test-go-action_windows_386 (deflated 46%) -----> Build is complete. List of files at /github/workspace/.release: -total 16436 -drwxr-xr-x 2 root root 4096 Feb 5 00:03 . -drwxr-xr-x 5 root root 4096 Feb 5 00:02 .. --rw-r--r-- 1 root root 978566 Feb 5 00:02 test-go-action_darwin_386.zip --rw-r--r-- 1 root root 1008819 Feb 5 00:02 test-go-action_darwin_amd64.zip --rw-r--r-- 1 root root 918555 Feb 5 00:02 test-go-action_linux_386.zip --rw-r--r-- 1 root root 952985 Feb 5 00:02 test-go-action_linux_amd64.zip --rw-r--r-- 1 root root 930942 Feb 5 00:03 test-go-action_windows_386.zip --rw-r--r-- 1 root root 972286 Feb 5 00:02 test-go-action_windows_amd64.zip -``` diff --git a/.github/builder/entrypoint.sh b/.github/builder/entrypoint.sh deleted file mode 100755 index 2f753f7..0000000 --- a/.github/builder/entrypoint.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -set -e - -if [[ -z "$GITHUB_WORKSPACE" ]]; then - echo "Set the GITHUB_WORKSPACE env variable." - exit 1 -fi - -if [[ -z "$GITHUB_REPOSITORY" ]]; then - echo "Set the GITHUB_REPOSITORY env variable." - exit 1 -fi - -if [[ -z "$GITHUB_REF" ]]; then - echo "Set the GITHUB_REF env variable." - exit 1 -fi - -# Regex and validate-version function adapted from https://github.com/fsaintjacques/semver-tool/blob/master/src/semver -SEMVER_REGEX="^[v]?(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(\\-[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?(\\+[0-9A-Za-z-]+(\\.[0-9A-Za-z-]+)*)?$" - -function validate-version { - local version=$1 - if [[ "$version" =~ $SEMVER_REGEX ]]; then - # if a second argument is passed, store the result in var named by $2 - if [ "$#" -eq "2" ]; then - local major=${BASH_REMATCH[1]} - local minor=${BASH_REMATCH[2]} - local patch=${BASH_REMATCH[3]} - local prere=${BASH_REMATCH[4]} - local build=${BASH_REMATCH[5]} - eval "$2=(\"$major\" \"$minor\" \"$patch\" \"$prere\" \"$build\")" - else - echo "$version" - fi - else - echo -e "version '$version' does not match the semver scheme 'X.Y.Z(-PRERELEASE)(+BUILD)'. Ensure this action is being run for a tag and not a branch." >&2 - exit 1 - fi -} - -root_path="/go/src/github.com/$GITHUB_REPOSITORY" -release_path="$GITHUB_WORKSPACE/.release" -repo_name="$(echo $GITHUB_REPOSITORY | cut -d '/' -f2)" -targets=${@-"darwin/amd64 darwin/386 darwin/arm64 linux/amd64 linux/386 windows/amd64 windows/386"} -version="${GITHUB_REF##*/}" - -validate-version $version - -echo "----> Setting up Go repository" -mkdir -p $release_path -mkdir -p $root_path -echo "----> $GITHUB_WORKSPACE contents" -ls $GITHUB_WORKSPACE/ -cp -a $GITHUB_WORKSPACE/* $root_path/ -cd $root_path - -for target in $targets; do - os="$(echo $target | cut -d '/' -f1)" - arch="$(echo $target | cut -d '/' -f2)" - output="${release_path}/${repo_name}_${os}_${arch}_${version}" - binary_name="${release_path}/${repo_name}_${version}" - - if [[ "$os" == "windows" ]]; then - binary_name="$binary_name.exe" - fi - - echo "----> Building project for: $target" - GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -o $binary_name - zip -j $output.zip $binary_name > /dev/null - rm -rf $binary_name -done - -echo "----> Build is complete. List of files at $release_path:" -cd $release_path -ls -al diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 47b6141..d75cb08 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,32 +4,33 @@ on: tags: - v* jobs: - build: - name: Build + goreleaser: + name: Build and publish to registry runs-on: ubuntu-latest - env: - GO111MODULE: on steps: - - uses: actions/checkout@v1 - - uses: ./.github/builder - - uses: actions/upload-artifact@v1 + - name: Checkout + uses: actions/checkout@v2 + + - name: Unshallow + run: git fetch --prune --unshallow + + - name: Set up Go + uses: actions/setup-go@v2 with: - name: binaries - path: .release - publish: - name: Publish - needs: build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/download-artifact@v1 + go-version: 1.16 + + - name: Import GPG key + id: import_gpg + uses: crazy-max/ghaction-import-gpg@v6 with: - name: binaries - path: .release - - name: github-upload-release - uses: docker://moonswitch/github-upload-release:master + gpg_private_key: ${{ secrets.BOT_GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.BOT_GPG_PASSPHRASE }} + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist env: + GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - args: not actor nektos/act - diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..33b5140 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,52 @@ +# Visit https://goreleaser.com for documentation on how to customize this +# behavior. +# Modified from https://raw.githubusercontent.com/hashicorp/terraform-provider-scaffolding/master/.goreleaser.yml +builds: + - env: + # goreleaser does not work with CGO, it could also complicate + # usage by users in CI/CD systems like Terraform Cloud where + # they are unable to install libraries. + - CGO_ENABLED=0 + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}' + goos: + - windows + - linux + - darwin + goarch: + - amd64 + - '386' + - arm + - arm64 + ignore: + - goos: darwin + goarch: '386' + - goos: windows + goarch: 'arm64' + binary: '{{ .ProjectName }}_v{{ .Version }}' +archives: + - format: zip + name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}' +checksum: + name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS' + algorithm: sha256 +signs: + - artifacts: checksum + args: + # if you are using this is a GitHub action or some other automated pipeline, you + # need to pass the batch flag to indicate its not interactive. + - "--batch" + - "--local-user" + - "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key + - "--output" + - "${signature}" + - "--detach-sign" + - "${artifact}" +release: +# If you want to manually examine the release before its live, uncomment this line: +# draft: true +changelog: + skip: true \ No newline at end of file