Skip to content

Commit

Permalink
Merge pull request #1 from cashapp/gotip
Browse files Browse the repository at this point in the history
Build and release gotip.
  • Loading branch information
alecthomas authored Dec 1, 2021
2 parents d9183cc + fbb14d9 commit ad86342
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/gotip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches:
- gotip
schedule:
# * is a special character in YAML so you have to quote this string
- cron: '0 12 * * *'
jobs:
gotip:
name: Build Go Tip
runs-on: ubuntu-latest
strategy:
matrix:
arch: [arm64, amd64]
os: [linux, darwin]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Init Hermit
run: ./bin/hermit env --raw >> $GITHUB_ENV
- name: Build Go
run: make GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} -C gotip
- name: Upload Release
uses: ncipollo/release-action@v1
with:
tag: gotip
allowUpdates: true
artifacts: "gotip/go-*.tbz"
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gotip/goroot
gotip/go-*
1 change: 1 addition & 0 deletions bin/.go@latest.pkg
1 change: 1 addition & 0 deletions bin/.make-4.3.pkg
1 change: 1 addition & 0 deletions bin/go
52 changes: 52 additions & 0 deletions bin/go-main-stubs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
#
#
# This script generates stub scripts for every Go "main" package in this
# repository. These stubs execute the corresponding main package via "go run".
#

set -euo pipefail

usage() {
echo "$(basename $0) [-c] -- create or clean Go main stub scripts"
exit 1
}

bindir="$(dirname $0)"
root="$(dirname "${bindir}")"

clean() {
grep -l "^# go-main-stubs stub script" "${bindir}"/* | grep -v bin/go-main-stubs | xargs rm || true
}

while getopts ":hc" arg; do
case $arg in
c)
echo "Cleaning old stubs"
clean
exit 0
;;
h | *)
usage
exit 0
;;
esac
done

clean

echo "Creating Go main stubs in ${bindir}"

echo -n .

for main in $(cd "${root}" && go list -f '{{if eq "main" .Name}}{{.ImportPath}}{{end}}' ./...); do
stub_script="${bindir}/$(basename $main)"
cat << EOF > ${stub_script}
#!/bin/bash
# go-main-stubs stub script
exec "\$(dirname \$0)/go" run $main "\$@"
EOF
chmod +x "${stub_script}"
echo -n .
done
echo
1 change: 1 addition & 0 deletions bin/gofmt
1 change: 1 addition & 0 deletions bin/make
17 changes: 17 additions & 0 deletions gotip/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export GOOS ?= $(shell go env GOOS)
export GOARCH ?= $(shell go env GOARCH)

BOOTSTRAP = go-$(GOOS)-$(GOARCH)-bootstrap
OUT = go-tip-$(GOOS)-$(GOARCH).tbz

gotip: clean
if test -d goroot; then \
cd goroot && git pull; \
else \
git clone --depth=1 https://go.googlesource.com/go goroot; \
fi
cd goroot/src && ./bootstrap.bash
mv $(BOOTSTRAP).tbz $(OUT)

clean:
rm -rf $(BOOTSTRAP).tbz $(BOOTSTRAP)

0 comments on commit ad86342

Please sign in to comment.