diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 00000000..8f61994d --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,109 @@ +name: goreleaser + +on: + pull_request: + push: + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Unshallow (for CHANGELOG) + run: git fetch --prune --unshallow + + - uses: actions/setup-go@v2 + with: + go-version: 1.x + + - name: Verify + run: | + go vet ./... + go test ./... + go fmt ./... + go mod tidy + go mod verify + git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]] + + # - name: Set CURRENT_TAG + # run: | + # CURRENT_TAG=M.m.p + # if [[ "$GITHUB_REF" =~ ^refs/tags/ ]]; then CURRENT_TAG=${GITHUB_REF#refs/tags/}; fi + # echo "::set-env name=CURRENT_TAG::$CURRENT_TAG" + + - name: Build + uses: goreleaser/goreleaser-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + version: latest # FIXME: https://github.com/goreleaser/goreleaser-action/issues/157 + args: release --rm-dist --snapshot --skip-publish + + # - name: Test + # run: | + # tar zxvf ./dist/monkey-Linux-x86_64.tar.gz -C . + # SHORT_COMMIT=$(cut -c-7 <<<$GITHUB_SHA) + # ./monkey -h | grep $SHORT_COMMIT + # ./monkey help | grep monkey + # ./monkey version + # [[ $(./monkey version | wc -l) = 1 ]] + # ./monkey version | grep $CURRENT_TAG + # ./monkey --version | grep $SHORT_COMMIT + # rm ./monkey + + # - name: Publish + # uses: goreleaser/goreleaser-action@v1 + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # with: + # version: latest # FIXME: https://github.com/goreleaser/goreleaser-action/issues/157 + # args: release --rm-dist + # if: startsWith(github.ref, 'refs/tags/') + + + # install-on-ubuntu: + # runs-on: ubuntu-latest + # if: startsWith(github.ref, 'refs/tags/') + # needs: goreleaser + # steps: + # - run: echo $PATH + # - run: 'while read -d: -r path; do ls -lhd $path || echo $path; done <<<"$PATH"' + # - run: '! which monkey' + # - run: '! monkey help' + # - run: curl -#fL https://git.io/FuzzyMonkey | BINDIR=/usr/share/rust/.cargo/bin sh -ex + # - run: monkey help + # - run: monkey version + + # install-on-macos: + # runs-on: macos-latest + # if: startsWith(github.ref, 'refs/tags/') + # needs: goreleaser + # steps: + # - run: echo $PATH + # - run: 'while read -d: -r path; do ls -lhd $path || echo $path; done <<<"$PATH"' + # - run: '! which monkey' + # - run: '! monkey help' + # - run: curl -#fL https://git.io/FuzzyMonkey | BINDIR=/usr/local/bin sh -ex + # - run: monkey help + # - run: monkey version + + # install-on-windows: + # runs-on: windows-latest + # if: startsWith(github.ref, 'refs/tags/') + # needs: goreleaser + # steps: + # - run: echo $PATH + # shell: bash + # - run: 'while read -d: -r path; do ls -lhd $path || echo $path; done <<<"$PATH"' + # shell: bash + # - run: '! which monkey' + # shell: bash + # - run: '! monkey help' + # shell: bash + # - run: curl -#fL https://git.io/FuzzyMonkey | BINDIR=/c/npm/prefix sh -ex + # shell: bash + # - run: monkey help + # shell: bash + # - run: monkey version + # shell: bash diff --git a/.gitignore b/.gitignore index d6b334b5..0c27b7a2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ # Binary created by 'go build' /bazelisk + +# Folder created by 'goreleaser build' or 'goreleaser release' +/dist/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..8e24695f --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,194 @@ +builds: +- env: + - CGO_ENABLED=0 + goos: + # - darwin + - linux + # - windows + goarch: # Platforms of snapcraft.io: amd64 arm64 armhf i386 ppc64el s390x + - 386 + - amd64 + - arm + - arm64 + - ppc64 + - s390x + goarm: + - 7 + ignore: [] + ldflags: + - '-extldflags "-static"' + - '-s -w' + +# archives: +# - replacements: +# # $(uname -s) and $(uname -m) +# 386: i386 +# amd64: x86_64 +# # arm64: aarch64 +# darwin: Darwin +# freebsd: FreeBSD +# linux: Linux +# windows: Windows +# format_overrides: +# - goos: windows +# format: zip +# # name_template: '{{.ProjectName}}-{{.Os}}-{{.Arch}}{{if .Arm}}v{{.Arm}}{{end}}' +# name_template: '{{.ProjectName}}-{{.Os}}-{{.Arch}}' + +checksum: + name_template: checksums.sha256.txt + algorithm: sha256 + +signs: +- artifacts: none + +# TODO: homebrew +# TODO: apt + +snapcrafts: +- id: bazelisk + + # Build IDs for the builds you want to create snapcraft packages for. + # Defaults to all builds. + # builds: + # - foo + # - bar + + # You can change the name of the package. + # Default: `{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}` + # name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + + # Replacements for GOOS and GOARCH in the package name. + # Keys should be valid GOOSs or GOARCHs. + # Values are the respective replacements. + # Default is empty. + # replacements: + # amd64: 64-bit + # 386: 32-bit + # darwin: macOS + # linux: Tux + + # The name of the snap. This is optional. + # Default is project name. + # name: drumroll + + # Wether to publish the snap to the snapcraft store. + # Remember you need to `snapcraft login` first. + # Defaults to false. + # publish: true + + # Single-line elevator pitch for your amazing snap. + # 79 char long at most. + summary: A user-friendly launcher for Bazel. + + # This the description of your snap. You have a paragraph or two to tell the + # most important story about your snap. Keep it under 100 words though, + # we live in tweetspace and your description wants to look good in the snap + # store. + description: > + Bazelisk is a wrapper for Bazel written in Go. + It automatically picks a good version of Bazel + given your current working directory, + downloads it from the official server (if required) + and then transparently passes through all command-line arguments + to the real Bazel binary. + You can call it just like you would call Bazel. + + # A guardrail to prevent you from releasing a snap to all your users before + # it is ready. + # `devel` will let you release only to the `edge` and `beta` channels in the + # store. `stable` will let you release also to the `candidate` and `stable` + # channels. More info about channels here: + # https://snapcraft.io/docs/reference/channels + # grade: stable + grade: devel + + # Snaps can be setup to follow three different confinement policies: + # `strict`, `devmode` and `classic`. A strict confinement where the snap + # can only read and write in its own namespace is recommended. Extra + # permissions for strict snaps can be declared as `plugs` for the app, which + # are explained later. More info about confinement here: + # https://snapcraft.io/docs/reference/confinement + # confinement: strict + confinement: classic + + # Your app's license, based on SPDX license expressions: https://spdx.org/licenses + # Default is empty. + license: Apache-2.0 + + # A snap of type base to be used as the execution environment for this snap. + # Valid values are: + # * bare - Empty base snap; + # * core - Ubuntu Core 16; + # * core18 - Ubuntu Core 18. + # Default is empty. + # base: core18 + + # Add extra files on the resulting snap. Useful for including wrapper + # scripts or other useful static files. Source filenames are relative to the + # project directory. Destination filenames are relative to the snap prime + # directory. + # Default is empty. + # extra_files: + # - source: drumroll.wrapper + # destination: bin/drumroll.wrapper + # mode: 0755 + + # snap access python path + # https://forum.snapcraft.io/t/how-do-i-allow-a-snap-to-access-pythonpath/16943/3 + # https://gitlab.com/inkscape/inkscape/-/blob/master/snap/snapcraft.yaml#L122 + # https://snapcraft.io/docs/python-apps + parts: + bazelisk: + python-deps: + plugin: python + # python-packages: + # - numpy + # - six + stage-packages: + - numpy + - six + + # Each binary built by GoReleaser is an app inside the snap. In this section + # you can declare extra details for those binaries. It is optional. + apps: + + # The name of the app must be the same name as the binary built or the snapcraft name. + bazelisk: + + # If your app requires extra permissions to work outside of its default + # confined space, declare them here. + # You can read the documentation about the available plugs and the + # things they allow: + # https://snapcraft.io/docs/reference/interfaces. + plugs: + - home + - network + # - personal-files + + # If you want your app to be autostarted and to always run in the + # background, you can make it a simple daemon. + # daemon: simple + + # If you any to pass args to your binary, you can add them with the + # args option. + # args: --foo + + # Bash completion snippet. More information about completion here: + # https://docs.snapcraft.io/tab-completion-for-snaps. + # completer: drumroll-completion.bash + + # You can override the command name. + # Defaults is the app name. + # command: bin/drumroll.wrapper + + # Allows plugs to be configured. Plugs like system-files and personal-files + # require this. + # Default is empty. + plugs: + # personal-files: + # read: + # - $HOME/.foo + # write: + # - $HOME/.foo + # - $HOME/.foobar diff --git a/go.mod b/go.mod index a129e81f..fe2f03fb 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/bazelbuild/bazelisk go 1.15 require ( + github.com/bazelbuild/rules_go v0.24.2 github.com/hashicorp/go-version v1.2.0 github.com/mitchellh/go-homedir v1.1.0 ) diff --git a/go.sum b/go.sum index 1b30763a..989e088a 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/bazelbuild/rules_go v0.24.2 h1:ajf4tKZXP8GQ/+7Ava1jgMUKSfuCIsqn6NlTIbWjzAI= +github.com/bazelbuild/rules_go v0.24.2/go.mod h1:MC23Dc/wkXEyk3Wpq6lCqz0ZAYOZDw2DR5y3N1q2i7M= github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=