-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99d9433
commit f444f08
Showing
6 changed files
with
129 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,77 @@ | ||
name: release | ||
concurrency: | ||
group: build-${{ github.ref }} | ||
cancel-in-progress: true | ||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
create-release: | ||
upload-binaries: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- name: setup-go | ||
uses: actions/setup-go@v3 | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.19 | ||
go-version: 1.22 | ||
cache: true | ||
cache-dependency-path: go.sum | ||
- run: | | ||
GOOS=darwin GOARCH=amd64 go build -o ./bin/nix-search-darwin-amd64 ./cmd/nix-search | ||
GOOS=darwin GOARCH=arm64 go build -o ./bin/nix-search-darwin-arm64 ./cmd/nix-search | ||
GOOS=linux GOARCH=arm64 go build -o ./bin/nix-search-linux-arm64 ./cmd/nix-search | ||
GOOS=linux GOARCH=amd64 go build -o ./bin/nix-search-linux-amd64 ./cmd/nix-search | ||
- run: | | ||
commit_sha="$(git rev-parse --short HEAD)" | ||
timestamp="$(date +%s)" | ||
release_name="release-$timestamp-$commit_sha" | ||
token=${{ secrets.GITHUB_TOKEN }} | ||
# https://docs.github.com/en/rest/releases/releases#create-a-release | ||
# https://stackoverflow.com/questions/45240336/how-to-use-github-release-api-to-make-a-release-without-source-code | ||
upload_url=$(curl -s -H "Authorization: token $token" \ | ||
-d "{\"tag_name\": \"$release_name\", \"name\":\"$release_name\",\"target_comitish\": \"$commit_sha\"}" \ | ||
"https://api.github.com/repos/peterldowns/nix-search-cli/releases" | jq -r '.upload_url') | ||
upload_url="${upload_url%\{*}" | ||
curl -s -H "Authorization: token $token" \ | ||
- name: release-darwin-amd64 | ||
run: | | ||
ldflags=$(./scripts/golang-ldflags.sh) | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags "$ldflags" -o ./bin/nix-search-darwin-amd64 ./cmd/nix-search | ||
upload_url=$(./scripts/upsert-gh-release.sh) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN}}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @bin/nix-search-darwin-amd64 \ | ||
"$upload_url?name=nix-search-darwin-amd64&label=nix-search-darwin-amd64" | ||
curl -s -H "Authorization: token $token" \ | ||
bottle_name=$(./scripts/make-bottle.sh ./bin/nix-search-darwin-amd64 monterey) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN}}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @"${bottle_name}" \ | ||
"$upload_url?name=${bottle_name}&label=${bottle_name}" | ||
- name: release-darwin-arm64 | ||
run: | | ||
ldflags=$(./scripts/golang-ldflags.sh) | ||
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags "$ldflags" -o ./bin/nix-search-darwin-arm64 ./cmd/nix-search | ||
upload_url=$(./scripts/upsert-gh-release.sh) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @bin/nix-search-darwin-arm64 \ | ||
"$upload_url?name=nix-search-darwin-arm64&label=nix-search-darwin-arm64" | ||
curl -s -H "Authorization: token $token" \ | ||
bottle_name=$(./scripts/make-bottle.sh ./bin/nix-search-darwin-arm64 arm64_monterey) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN}}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @"${bottle_name}" \ | ||
"$upload_url?name=${bottle_name}&label=${bottle_name}" | ||
- name: release-linux-arm64 | ||
run: | | ||
ldflags=$(./scripts/golang-ldflags.sh) | ||
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "$ldflags" -o ./bin/nix-search-linux-arm64 ./cmd/nix-search | ||
upload_url=$(./scripts/upsert-gh-release.sh) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @bin/nix-search-linux-arm64 \ | ||
"$upload_url?name=nix-search-linux-arm64&label=nix-search-linux-arm64" | ||
curl -s -H "Authorization: token $token" \ | ||
bottle_name=$(./scripts/make-bottle.sh ./bin/nix-search-linux-arm64 arm64_linux) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN}}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @"${bottle_name}" \ | ||
"$upload_url?name=${bottle_name}&label=${bottle_name}" | ||
- name: release-linux-amd64 | ||
run: | | ||
ldflags=$(./scripts/golang-ldflags.sh) | ||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$ldflags" -o ./bin/nix-search-linux-amd64 ./cmd/nix-search | ||
upload_url=$(./scripts/upsert-gh-release.sh) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @bin/nix-search-linux-amd64 \ | ||
"$upload_url?name=nix-search-linux-amd64&label=nix-search-linux-amd64" | ||
bottle_name=$(./scripts/make-bottle.sh ./bin/nix-search-linux-amd64 x86_64_linux) | ||
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN}}" \ | ||
-H "Content-Type: application/octet-stream" \ | ||
--data-binary @"${bottle_name}" \ | ||
"$upload_url?name=${bottle_name}&label=${bottle_name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
# Attempts to get an upload URL for adding assets to the current | ||
# Github Release. It does this by attemping to create the release, | ||
# then reading it if it already exists. | ||
# | ||
# On success, the result is a 0 status code and a valid upload URL. | ||
# | ||
# Docs: | ||
# https://docs.github.com/en/rest/releases/releases#create-a-release | ||
# https://stackoverflow.com/questions/45240336/how-to-use-github-release-api-to-make-a-release-without-source-code | ||
version=$(cat ./VERSION) | ||
commit_sha=$(git rev-parse --short HEAD || echo 'unknown') | ||
# https://semver.org/#spec-item-10 | ||
release_name="$version+commit.$commit_sha" | ||
if ! upload_url=$( | ||
gh api --method POST 'repos/{owner}/{repo}/releases' \ | ||
-F "tag_name=$release_name" \ | ||
-F "name=$release_name" \ | ||
-F "target_comitish=$commit_sha" \ | ||
--jq '.upload_url' \ | ||
); then | ||
if ! upload_url=$( | ||
gh api --method GET 'repos/{owner}/{repo}/releases/tags/'"$release_name" \ | ||
--jq '.upload_url' \ | ||
); then | ||
exit 1 | ||
fi | ||
fi | ||
# the upload url looks like | ||
# https://uploads.github.com/.../<release_id>/assets{?name,label} | ||
# this trick strips off the {?name,label} | ||
upload_url="${upload_url%\{*}" | ||
echo "$upload_url" | ||
|