Skip to content

Commit

Permalink
feat(cd): use goreleaser (#56)
Browse files Browse the repository at this point in the history
Signed-off-by: Amine Kherbouche <[email protected]>
  • Loading branch information
kaminek authored Apr 16, 2021
1 parent 1618acf commit 9fc7819
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 104 deletions.
78 changes: 15 additions & 63 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,46 @@ name: Publish
on:
push:
tags:
- 'v*.*'
- 'v*.*.*'

jobs:
publish_release:
name: Release

runs-on: ubuntu-latest

strategy:
fail-fast: true

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Build
run: make build-all
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Test
run: make test
- name: Get tag version
id: git
run: echo "::set-output name=tag_version::$(make version)"

- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
tag_name: ${{ steps.git.outputs.tag_version }}
release_name: Release ${{ steps.git.outputs.tag_version }}
draft: 'false'
prerelease: 'false'

- name: Upload Linux release executable
uses: actions/[email protected]
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/upctl-${{ steps.git.outputs.tag_version }}-linux-amd64
asset_name: upctl-${{ steps.git.outputs.tag_version }}-linux-amd64
asset_content_type: application/x-binary

- name: Upload Darwin release executable
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/upctl-${{ steps.git.outputs.tag_version }}-darwin-amd64
asset_name: upctl-${{ steps.git.outputs.tag_version }}-darwin-amd64
asset_content_type: application/x-binary

- name: Upload Windows release executable
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/upctl-${{ steps.git.outputs.tag_version }}-windows-amd64.exe
asset_name: upctl-${{ steps.git.outputs.tag_version }}-windows-amd64.exe
asset_content_type: application/x-dosexec

- name: Generate SHA256 file
run: ./scripts/generate_sha256_file.sh

- name: Upload SHA256SUMS file
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./bin/SHA256SUMS
asset_name: SHA256SUMS
asset_content_type: text/plain
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN}}

- name: Generate AUR PKGBUILD
run: ./scripts/generate_aur_pkgbuild.sh ${{ steps.git.outputs.tag_version }}

- name: Publish AUR package
uses: KSXGitHub/[email protected]
with:
pkgname: upctl
pkgname: upcloud-cli
pkgbuild: PKGBUILD
commit_username: ${{ secrets.AUR_USERNAME }}
commit_email: ${{ secrets.AUR_EMAIL }}
ssh_private_key: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
commit_message: Release ${{ steps.git.outputs.tag_version }}
force_push: true

5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.13.x, 1.14.x, 1.15.x]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v1
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
go-version: 1.16
- name: Checkout
uses: actions/checkout@v2
- name: Run unit tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ vendor/
.idea/

.DS_Store
dist/
188 changes: 188 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Make sure to check the documentation at http://goreleaser.com
#
before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
- GO_MODULE_NAME=github.com/UpCloudLtd/upcloud-cli
goos:
- linux
- windows
- darwin
- freebsd
goarch:
- amd64
- arm64
main: ./cmd/upctl/main.go
binary: upctl
flags:
- -v
ldflags:
- -s -w
- -X {{.Env.GO_MODULE_NAME}}/internal/config.Version={{.Version}}
- -X {{.Env.GO_MODULE_NAME}}/internal/config.BuildDate={{.Date}}

archives:
-
replacements:
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-next"

changelog:
sort: asc

nfpms:
-
# Name of the package.
# Defaults to `ProjectName`.
package_name: upcloud-cli

# You can change the file name of the package.
# Default: `{{ .PackageName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}`
file_name_template: "{{ .ProjectName }}-{{ .Version }}_{{ .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:
386: 32-bit
darwin: macOS

# Your app's vendor.
# Default is empty.
vendor: UpCloudLtd.
# Your app's homepage.
# Default is empty.
homepage: https://upcloud.com/

# Your app's maintainer (probably you).
# Default is empty.
maintainer: UpCloud team <[email protected]>

# Your app's description.
# Default is empty.
description: CLI tool for managing UpCloud services.

# Your app's license.
# Default is empty.
license: MIT

# Formats to be generated.
formats:
- apk
- deb
- rpm

# Packages your package depends on.
# dependencies:
# - bash-completion

# Packages your package recommends installing.
recommends:
- bash-completion

overrides:
rpm:
replacements:
amd64: x86_64

# Custon configuration applied only to the RPM packager.
rpm:
# The package group. This option is deprecated by most distros
# but required by old distros like CentOS 5 / EL 5 and earlier.
group: Unspecified

# # Compression algorithm.
# compression: lzma

# Custom configuration applied only to the Deb packager.
deb:
# Custom deb special files.

brews:
-
# GOARM to specify which 32-bit arm version to use if there are multiple versions
# from the build section. Brew formulas support atm only one 32-bit version.
# Default is 6 for all artifacts or each id if there a multiple versions.
goarm: 6

# NOTE: make sure the url_template, the token and given repo (github or gitlab) owner and name are from the
# same kind. We will probably unify this in the next major version like it is done with scoop.

# GitHub/GitLab repository to push the formula to
# Gitea is not supported yet, but the support coming
tap:
owner: UpCloudLtd
name: homebrew-tap
# Optionally a token can be provided, if it differs from the token provided to GoReleaser
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"

# Allows you to set a custom download strategy. Note that you'll need
# to implement the strategy and add it to your tap repository.
# Example: https://docs.brew.sh/Formula-Cookbook#specifying-the-download-strategy-explicitly
# Default is empty.
# download_strategy: CurlDownloadStrategy.

# Git author used to commit to the repository.
# Defaults are shown.
commit_author:
name: goreleaserbot
email: [email protected]

# Folder inside the repository to put the formula.
# Default is the root folder.
folder: Formula

# Your app's homepage.
# Default is empty.
homepage: "https://upcloud.com/"

# Your app's description.
# Default is empty.
description: "CLI tool for managing UpCloud services."

# SPDX identifier of your app's license.
# Default is empty.
license: "MIT"

# Setting this will prevent goreleaser to actually try to commit the updated
# formula - instead, the formula file will be stored on the dist folder only,
# leaving the responsibility of publishing it to the user.
# If set to auto, the release will not be uploaded to the homebrew tap
# in case there is an indicator for prerelease in the tag e.g. v1.0.0-rc1
# Default is false.
# skip_upload: true

# Custom block for brew.
# Can be used to specify alternate downloads for devel or head releases.
# Default is empty.
custom_block: |
head "https://github.com/UpCloudLtd/upcloud-cli.git"
# Packages your package depends on.
dependencies:
- name: bash-completion
type: optional

# Custom install script for brew.
install: |
bin.install "upctl"
#
# So you can `brew test` your formula.
# Default is empty.
test: |
system "#{bin}/upctl version"
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ To use upctl, download the upctl binary from the
### macOS

```bash
sudo curl -o /usr/local/bin/upctl https://github.com/UpCloudLtd/upcloud-cli/releases/download/v<VERSION>/upctl-v<VERSION>-darwin-amd64
sudo chmod +x /usr/local/bin/upctl
brew tap UpCloudLtd/tap
brew install upcloud-cli
upctl -h
```

Expand All @@ -51,8 +51,17 @@ echo "[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion"

### Linux

## AUR
```
yay -S upcloud-cli
```

## Other distros

Use the package corresponding to your distro (deb, rpm, apk), example Debian like:

```bash
sudo curl -o /usr/local/bin/upctl https://github.com/UpCloudLtd/upcloud-cli/releases/download/v<VERSION>/upctl-v<VERSION>-linux-amd64
sudo curl -o upcloud.deb https://github.com/kaminek/upcloud-cli/releases/download/v<VERSION>/upcloud-cli-<VERSION>_amd64.deb
sudo chmod +x /usr/local/bin/upctl
upctl -h
```
Expand All @@ -67,7 +76,8 @@ echo "[ -f /etc/bash_completion ] && . /etc/bash_completion" >> ~/.bash_profile

### Windows
```bash
Invoke-WebRequest -Uri "https://github.com/UpCloudLtd/upcloud-cli/releases/download/v<VERSION>/upctl-v<VERSION>-windows-amd64" -OutFile "upctl.exe"
Invoke-WebRequest -Uri "https://github.com/UpCloudLtd/upcloud-cli/releases/download/v<VERSION>/upcloud-cli-<VERSION>_windows_x86_64.zip" -OutFile "upcloud-cli.zip"
unzip upcloud-cli.zip
upctl.exe -h
```

Expand Down
21 changes: 5 additions & 16 deletions scripts/generate_aur_pkgbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,23 @@ if [ "$#" -ne 1 ]; then
exit 1
fi

PKG_VERSION=$1
PKG_VERSION="${1:1}"
PKG_HASH="SKIP"

cat > PKGBUILD <<EOF
pkgname=upctl
pkgname=upcloud-cli
pkgver=${PKG_VERSION}
pkgrel=1
pkgdesc="upctl - a CLI tool for managing UpCloud services."
arch=('x86_64')
url="https://upcloud.com"
license=('Apache')
makedepends=('go' 'git')
source=("https://github.com/UpCloudLtd/\$pkgname/archive/\${pkgver}.tar.gz")
source=("https://github.com/kaminek/\${pkgname}/releases/download/v\${pkgver}/\${pkgname}_\${pkgver}_linux_x86_64.tar.gz")
sha256sums=('${PKG_HASH}')
build() {
cd "\$pkgname-\$pkgver"
make build
}
check() {
cd "\$pkgname-\$pkgver"
make test
}
package() {
cd "\$pkgname-\$pkgver"
install -Dm755 bin/upctl "\$pkgdir/usr/local/bin/upctl"
cd "\$pkgname_\$pkgver_linux_x86_64"
install -Dm755 upctl "\$pkgdir/usr/local/bin/upctl"
}
EOF

Expand Down
Loading

0 comments on commit 9fc7819

Please sign in to comment.