From 0a4aa50f4eee872fcca2bb2cc98d6bc78d06d09a Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Fri, 11 Nov 2022 01:17:06 -0800 Subject: [PATCH 01/33] ci/release: Checkpoint --- ci/release/README.md | 3 + ci/release/build.sh | 34 ++++++++ ci/release/changelogs/next.md | 15 ++++ ci/release/changelogs/template.md | 13 ++++ ci/release/release.sh | 125 ++++++++++++++++++++++++++++++ ci/release/template/LICENSE.txt | 1 + ci/release/template/Makefile | 12 +++ ci/release/template/README.md.sh | 14 ++++ ci/release/template/bin/d2 | 0 ci/release/template/install.sh | 16 ++++ ci/release/template/lib.sh | 105 +++++++++++++++++++++++++ ci/release/template/uninstall.sh | 14 ++++ ci/sub | 2 +- cmd/d2/help.go | 2 +- 14 files changed, 354 insertions(+), 2 deletions(-) create mode 100644 ci/release/README.md create mode 100755 ci/release/build.sh create mode 100644 ci/release/changelogs/next.md create mode 100644 ci/release/changelogs/template.md create mode 100755 ci/release/release.sh create mode 120000 ci/release/template/LICENSE.txt create mode 100644 ci/release/template/Makefile create mode 100755 ci/release/template/README.md.sh create mode 100644 ci/release/template/bin/d2 create mode 100755 ci/release/template/install.sh create mode 100644 ci/release/template/lib.sh create mode 100755 ci/release/template/uninstall.sh diff --git a/ci/release/README.md b/ci/release/README.md new file mode 100644 index 000000000..af207b18d --- /dev/null +++ b/ci/release/README.md @@ -0,0 +1,3 @@ +# release + +Run `./release.sh --help` for instructions. diff --git a/ci/release/build.sh b/ci/release/build.sh new file mode 100755 index 000000000..5aea5df26 --- /dev/null +++ b/ci/release/build.sh @@ -0,0 +1,34 @@ +#!/bin/sh +set -eu +. "$(dirname "$0")/../../ci/sub/lib.sh" +. "$(dirname "$0")/../../ci/sub/golib.sh" +cd -- "$(dirname "$0")/../.." + +build() {( + OS="$1" + ARCH="$2" + BUILD_DIR="$BUILD_DIR/$OS/$ARCH" + + mkdir -p "$BUILD_DIR/bin" + sh_c cp LICENSE.txt "$BUILD_DIR" + sh_c "./ci/release/template/README.md.sh > $BUILD_DIR" + + export GOOS=$(goos "$OS") + export GOARCH="$ARCH" + sh_c go build -ldflags "-X lib/version.Version=$VERSION" \ + -o "$BUILD_DIR/bin/d2" ./cmd/d2 +)} + +main() { + VERSION="$(git_describe_ref)" + BUILD_DIR="ci/release/build/$VERSION" + + + runjob linux-amd64 'build linux amd64' & + runjob linux-arm64 'build linux arm64' & + runjob macos-amd64 'build macos amd64' & + runjob macos-arm64 'build macos arm64' & + wait_jobs +} + +main "$@" diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md new file mode 100644 index 000000000..1030a2961 --- /dev/null +++ b/ci/release/changelogs/next.md @@ -0,0 +1,15 @@ +## Summary 🍻 + +For v0.0.99 we focused on X, Y and Z. Enjoy! + +### Features 💸 + +- Now you can easily do x, y and z #9999 + +### Improvements 🔧 + +- Improves something or the other #9999 + +### Bugfixes 🔴 + +- Fixes something or the other #9999 diff --git a/ci/release/changelogs/template.md b/ci/release/changelogs/template.md new file mode 100644 index 000000000..501bb82d7 --- /dev/null +++ b/ci/release/changelogs/template.md @@ -0,0 +1,13 @@ +For v0.0.99 we focused on X, Y and Z. Enjoy! + +#### Features 💸 + +- Now you can easily do x, y and z #9999 + +#### Improvements 🔧 + +- Improves something or the other #9999 + +#### Bugfixes 🔴 + +- Fixes something or the other #9999 diff --git a/ci/release/release.sh b/ci/release/release.sh new file mode 100755 index 000000000..6eac14d10 --- /dev/null +++ b/ci/release/release.sh @@ -0,0 +1,125 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh + +help() { + cat < + +$0 implements the D2 release process. + +Flags: + +--rebuild: Normally the release script will avoid rebuilding release assets if they + already exist but if you changed something and need to force rebuild, use + this flag. +--pre-release: Pass to mark the release on GitHub as a pre-release. For pre-releases the + version format should include a suffix like v0.0.99-alpha.1 + As well, for pre-releases the script will not overwrite changelogs/next.md + with changelogs/template.md and instead keep it the same as + changelogs/v0.0.99-alpha.1.md. This is because you want to maintain the + changelog entries for the eventual final release. + +Process: + +Let's say you passed in v0.0.99 as the version: + +1. It creates branch v0.0.99 based on master if one does not already exist. + - It then checks it out. +2. It moves changelogs/next.md to changelogs/v0.0.99.md if there isn't already a + changelogs/v0.0.99.md. + - If the move occured, changelogs/next.md is replaced with changelogs/template.md. As + well, a git commit with title v0.0.99 will be created. +3. It pushes branch v0.0.99 to origin. +4. It creates a v0.0.99 git tag if one does not already exist. + If one does, it ensures the v0.0.99 tag points to the current commit. + Then it pushes the tag to origin. +5. It creates a draft GitHub release for the tag if one does not already exist. +6. It updates the GitHub release notes to match changelogs/v0.0.99.md. +7. It creates a draft PR for branch v0.0.99 into master if one does not already exist. +8. It builds the release assets if they do not exist. + Pass --rebuild to force rebuilding all release assets. +9. It uploads the release assets overwriting any existing assets on the release. + +Only a draft release will be created so do not fret if something goes wrong. +You can just rerun the script again as it is fully idempotent. + +To complete the release, merge the release PR and then publish the draft release. + +Testing: + +For testing, change the origin remote to a private throwaway repository and push master to +it. Then the PR, tag and draft release will be generated against said throwaway +repository. + +Example: + $0 v0.0.99 +EOF +} + +main() { + unset FLAG \ + FLAGRAW \ + FLAGARG \ + FLAGSHIFT \ + VERSION \ + REBUILD \ + PRERELEASE + while :; do + flag_parse "$@" + case "$FLAG" in + h|help) + help + return 0 + ;; + rebuild) + flag_noarg + REBUILD=1 + shift "$FLAGSHIFT" + ;; + pre-release) + flag_noarg + PRERELEASE=1 + shift "$FLAGSHIFT" + ;; + '') + shift "$FLAGSHIFT" + break + ;; + *) + flag_errusage "unrecognized flag $FLAGRAW" + ;; + esac + done + + if [ $# -ne 1 ]; then + flag_errusage "first argument must be release version like v0.0.99" + fi + VERSION="$1" + shift + + 1_branch + 2_changelog + 3_commit + 4_tag + 5_draft_release + 6_draft_pr + 7_build_assets + 9_upload_assets + + if [ "$(git_describe_ref)" != "$TAG" ]; then + git tag -am "$TAG" "$TAG" + fi + hide git push origin "$TAG" +} + +1_branch() { + +} + +7_build_assets() { + ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION +} + +main "$@" diff --git a/ci/release/template/LICENSE.txt b/ci/release/template/LICENSE.txt new file mode 120000 index 000000000..6932c6369 --- /dev/null +++ b/ci/release/template/LICENSE.txt @@ -0,0 +1 @@ +../../../LICENSE.txt \ No newline at end of file diff --git a/ci/release/template/Makefile b/ci/release/template/Makefile new file mode 100644 index 000000000..a93267ed7 --- /dev/null +++ b/ci/release/template/Makefile @@ -0,0 +1,12 @@ +.POSIX: +.SILENT: + +PREFIX = $(DESTDIR)/usr/local + +.PHONY: install +install: + ./scripts/install.sh + +.PHONY: uninstall +uninstall: + ./scripts/uninstall.sh diff --git a/ci/release/template/README.md.sh b/ci/release/template/README.md.sh new file mode 100755 index 000000000..4f4b2e082 --- /dev/null +++ b/ci/release/template/README.md.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu + +cat <&2 +} + +printferr() { + COLOR=1 printfp err "$@" >&2 +} + +sh_c() { + COLOR=3 echop exec "$*" + "$@" +} + +get_rand_color() { + # 1-6 are regular and 9-14 are bright. + # 1,2 and 9,10 are red and green but we use those for success and failure. + pick "$*" 3 4 5 6 11 12 13 14 +} + +echop() {( + prefix="$1" + shift + + if [ -z "${COLOR:-}" ]; then + COLOR="$(get_rand_color "$prefix")" + fi + printf '%s: %s\n' "$(setaf "$COLOR" "$prefix")" "$*" +)} + +printfp() {( + PREFIX="$1" + shift + echop "$PREFIX" "$(printf "$@")" +)} + +hide() { + out="$(mktemp)" + set +e + "$@" >"$out" 2>&1 + code="$?" + set -e + if [ "$code" -eq 0 ]; then + return + fi + cat "$out" >&2 + exit "$code" +} + +echo_dur() { + local dur=$1 + local h=$((dur/60/60)) + local m=$((dur/60%60)) + local s=$((dur%60)) + printf '%dh%dm%ds' "$h" "$m" "$s" +} + +sponge() { + dst="$1" + tmp="$(mktemp)" + cat > "$tmp" + cat "$tmp" > "$dst" +} + +stripansi() { + # First regex gets rid of standard xterm escape sequences for controlling + # visual attributes. + # The second regex I'm not 100% sure, the reference says it selects the US + # encoding but I'm not sure why that's necessary or why it always occurs + # in tput sgr0 before the standard escape sequence. + # See tput sgr0 | xxd + sed -e $'s/\x1b\[[0-9;]*m//g' -e $'s/\x1b(.//g' +} + +runtty() { + case "$(uname)" in + Darwin) + script -q /dev/null "$@" + ;; + Linux) + script -eqc "$*" + ;; + *) + echoerr "runtty: unsupported OS $(uname)" + esac +} diff --git a/ci/release/template/uninstall.sh b/ci/release/template/uninstall.sh new file mode 100755 index 000000000..2ec6a47c1 --- /dev/null +++ b/ci/release/template/uninstall.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu +. "$(dirname "$0")/lib.sh" + +main() { + if [ ! -e "${PREFIX:-}" ]; then + echoerr "\$PREFIX must be set to a unix prefix directory from which to uninstall d2 like /usr/local" + exit 1 + fi + + sh_c rm -f "$PREFIX/bin/d2" +} + +main "$@" diff --git a/ci/sub b/ci/sub index 7ff838089..ffe9df3b8 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 7ff8380897435e73d53e329a7cd39dc38c7ad227 +Subproject commit ffe9df3b89e12db7f1dc4ed9d5a25730dde5cc79 diff --git a/cmd/d2/help.go b/cmd/d2/help.go index affc2abf5..961c9c275 100644 --- a/cmd/d2/help.go +++ b/cmd/d2/help.go @@ -27,7 +27,7 @@ Subcommands: %[1]s layout - Lists available layout engine options with short help %[1]s layout [layout name] - Display long help for a particular layout engine -See more docs at https://oss.terrastruct.com/d2 +See more docs and the source code at https://oss.terrastruct.com/d2 `, ms.Name, ms.FlagHelp()) } From c3b41fd56aa079aeb7bd9ef1c9c17a9418b5c804 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 10:29:39 -0800 Subject: [PATCH 02/33] 2022-11-12 10:29:39am --- ci/release/changelogs/next.md | 8 ++--- ci/release/changelogs/v0.0.99.md | 13 +++++++ ci/release/release.sh | 58 +++++++++++++++++++++++++------- ci/sub | 2 +- 4 files changed, 62 insertions(+), 19 deletions(-) create mode 100644 ci/release/changelogs/v0.0.99.md diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 1030a2961..501bb82d7 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,15 +1,13 @@ -## Summary 🍻 - For v0.0.99 we focused on X, Y and Z. Enjoy! -### Features 💸 +#### Features 💸 - Now you can easily do x, y and z #9999 -### Improvements 🔧 +#### Improvements 🔧 - Improves something or the other #9999 -### Bugfixes 🔴 +#### Bugfixes 🔴 - Fixes something or the other #9999 diff --git a/ci/release/changelogs/v0.0.99.md b/ci/release/changelogs/v0.0.99.md new file mode 100644 index 000000000..501bb82d7 --- /dev/null +++ b/ci/release/changelogs/v0.0.99.md @@ -0,0 +1,13 @@ +For v0.0.99 we focused on X, Y and Z. Enjoy! + +#### Features 💸 + +- Now you can easily do x, y and z #9999 + +#### Improvements 🔧 + +- Improves something or the other #9999 + +#### Bugfixes 🔴 + +- Fixes something or the other #9999 diff --git a/ci/release/release.sh b/ci/release/release.sh index 6eac14d10..516b0aa19 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -99,26 +99,58 @@ main() { VERSION="$1" shift - 1_branch - 2_changelog - 3_commit - 4_tag - 5_draft_release - 6_draft_pr - 7_build_assets - 9_upload_assets + runjob ensure_branch + runjob ensure_changelog + runjob ensure_commit + # runjob push_branch + # 3_commit + # 4_tag + # 5_draft_release + # 6_draft_pr + # 7_build_assets + # 9_upload_assets - if [ "$(git_describe_ref)" != "$TAG" ]; then - git tag -am "$TAG" "$TAG" + # if [ "$(git_describe_ref)" != "$TAG" ]; then + # git tag -am "$TAG" "$TAG" + # fi + # hide git push origin "$TAG" +} + +ensure_branch() { + if [ -z "$(git branch --list "$VERSION")" ]; then + sh_c git branch "$VERSION" master fi - hide git push origin "$TAG" + sh_c git checkout -q "$VERSION" } -1_branch() { +ensure_changelog() { + if [ -f "./ci/release/changelogs/$VERSION.md" ]; then + return 0 + fi + sh_c cp "./ci/release/changelogs/next.md" "./ci/release/changelogs/$VERSION.md" + if [ -z "${PRERELEASE-}" ]; then + sh_c cp "./ci/release/changelogs/template.md" "./ci/release/changelogs/next.md" + fi } -7_build_assets() { +ensure_commit() { + sh_c git add --all + if ! git commit --dry-run >/dev/null; then + return 0 + fi + if [ "$(git show --no-patch --format=%s)" = "$VERSION" ]; then + sh_c git commit --amend --no-edit + else + sh_c git commit -m "$VERSION" + fi +} + +push_branch() { + sh_c git push -fu origin "$VERSION" +} + +ensure_built_assets() { ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION } diff --git a/ci/sub b/ci/sub index ffe9df3b8..a4961f772 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit ffe9df3b89e12db7f1dc4ed9d5a25730dde5cc79 +Subproject commit a4961f772d1f98bb7a8185a6590ed4346684e392 From 8425c46f64a6238e9518b0b5ed05cf3d8dc5e75c Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 11:17:30 -0800 Subject: [PATCH 03/33] ci/release/release.sh: Finish except for _8_ensure_assets --- ci/release/release.sh | 99 +++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 32 deletions(-) diff --git a/ci/release/release.sh b/ci/release/release.sh index 516b0aa19..99c18f85a 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -29,14 +29,17 @@ Let's say you passed in v0.0.99 as the version: - It then checks it out. 2. It moves changelogs/next.md to changelogs/v0.0.99.md if there isn't already a changelogs/v0.0.99.md. - - If the move occured, changelogs/next.md is replaced with changelogs/template.md. As - well, a git commit with title v0.0.99 will be created. -3. It pushes branch v0.0.99 to origin. -4. It creates a v0.0.99 git tag if one does not already exist. + - If the move occured, changelogs/next.md is replaced with changelogs/template.md. +3. If the current commit does not have a title of v0.0.99 then a new commit with said + title will be created with all uncommitted changes. + - If the current commit does, then the uncommitted changes will be amended to the commit. +4. It pushes branch v0.0.99 to origin. +5. It creates a v0.0.99 git tag if one does not already exist. If one does, it ensures the v0.0.99 tag points to the current commit. Then it pushes the tag to origin. -5. It creates a draft GitHub release for the tag if one does not already exist. -6. It updates the GitHub release notes to match changelogs/v0.0.99.md. +6. It creates a draft GitHub release for the tag if one does not already exist. + - It will also set the release notes to match changelogs/v0.0.99.md even + if the release already exists. 7. It creates a draft PR for branch v0.0.99 into master if one does not already exist. 8. It builds the release assets if they do not exist. Pass --rebuild to force rebuilding all release assets. @@ -99,31 +102,25 @@ main() { VERSION="$1" shift - runjob ensure_branch - runjob ensure_changelog - runjob ensure_commit - # runjob push_branch - # 3_commit - # 4_tag - # 5_draft_release - # 6_draft_pr - # 7_build_assets - # 9_upload_assets - - # if [ "$(git_describe_ref)" != "$TAG" ]; then - # git tag -am "$TAG" "$TAG" - # fi - # hide git push origin "$TAG" + runjob 1_ensure_branch _1_ensure_branch + runjob 2_ensure_changelog _2_ensure_changelog + runjob 3_ensure_commit _3_ensure_commit + runjob 4_push_branch _4_push_branch + runjob 5_ensure_tag _5_ensure_tag + runjob 6_ensure_release _6_ensure_release + runjob 7_ensure_pr _7_ensure_pr + runjob 8_ensure_assets _8_ensure_assets + runjob 9_upload_assets _9_upload_assets } -ensure_branch() { +_1_ensure_branch() { if [ -z "$(git branch --list "$VERSION")" ]; then sh_c git branch "$VERSION" master fi sh_c git checkout -q "$VERSION" } -ensure_changelog() { +_2_ensure_changelog() { if [ -f "./ci/release/changelogs/$VERSION.md" ]; then return 0 fi @@ -134,24 +131,62 @@ ensure_changelog() { fi } -ensure_commit() { +_3_ensure_commit() { sh_c git add --all - if ! git commit --dry-run >/dev/null; then - return 0 - fi if [ "$(git show --no-patch --format=%s)" = "$VERSION" ]; then sh_c git commit --amend --no-edit else - sh_c git commit -m "$VERSION" + sh_c git commit --allow-empty -m "$VERSION" fi } -push_branch() { - sh_c git push -fu origin "$VERSION" +_4_push_branch() { + if git rev-parse @{u} >/dev/null 2>&1; then + sh_c git push -f origin "refs/heads/$VERSION" + else + sh_c git push -fu origin "refs/heads/$VERSION" + fi } -ensure_built_assets() { - ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION +_5_ensure_tag() { + sh_c git tag --force -a "$VERSION" -m "$VERSION" + sh_c git push -f origin "refs/tags/$VERSION" +} + +_6_ensure_release() { + if gh release view "$VERSION" >/dev/null 2>&1; then + sh_c gh release edit \ + --draft \ + --notes-file "./ci/release/changelogs/$VERSION.md" \ + ${PRERELEASE:+--prerelease} \ + "--title=$VERSION" \ + "$VERSION" + return 0 + fi + sh_c gh release create \ + --draft \ + --notes-file "./ci/release/changelogs/$VERSION.md" \ + ${PRERELEASE:+--prerelease} \ + "--title=$VERSION" \ + "$VERSION" +} + +_7_ensure_pr() { + pr_url=$(gh pr view "$VERSION" --json=url '--template={{ .url }}' 2>/dev/null || true) + if [ -n "$pr_url" ]; then + _echo "PR already exists: $pr_url" + return 0 + fi + sh_c gh pr create --draft --fill +} + +_8_ensure_assets() { + # ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION + _echo TODO +} + +_9_upload_assets() { + sh_c gh release upload --clobber "$VERSION" "./ci/release/build/$VERSION"/*.tar.gz } main "$@" From b2a33c2cc652696d0c09067f6f18bf33fc0a7cf1 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 11:53:54 -0800 Subject: [PATCH 04/33] 2022-11-12 11:53:54am --- ci/release/build.sh | 15 +++++++------- ci/release/release.sh | 47 ++++++++++++++++++++++++++----------------- ci/sub | 2 +- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/ci/release/build.sh b/ci/release/build.sh index 5aea5df26..8da755f81 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -1,10 +1,9 @@ #!/bin/sh set -eu -. "$(dirname "$0")/../../ci/sub/lib.sh" -. "$(dirname "$0")/../../ci/sub/golib.sh" cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh -build() {( +build() { OS="$1" ARCH="$2" BUILD_DIR="$BUILD_DIR/$OS/$ARCH" @@ -17,17 +16,17 @@ build() {( export GOARCH="$ARCH" sh_c go build -ldflags "-X lib/version.Version=$VERSION" \ -o "$BUILD_DIR/bin/d2" ./cmd/d2 -)} +} main() { VERSION="$(git_describe_ref)" BUILD_DIR="ci/release/build/$VERSION" - runjob linux-amd64 'build linux amd64' & - runjob linux-arm64 'build linux arm64' & - runjob macos-amd64 'build macos amd64' & - runjob macos-arm64 'build macos arm64' & + runjob linux-amd64 'OS=linux ARCH=amd64 build linux amd64' & + runjob linux-arm64 'OS=linux ARCH=arm64 build linux arm64' & + runjob macos-amd64 'OS=macos ARCH=amd64 build macos amd64' & + runjob macos-arm64 'OS=macos ARCH=arm64 build macos arm64' & wait_jobs } diff --git a/ci/release/release.sh b/ci/release/release.sh index 99c18f85a..6e9a82835 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -102,15 +102,22 @@ main() { VERSION="$1" shift - runjob 1_ensure_branch _1_ensure_branch - runjob 2_ensure_changelog _2_ensure_changelog - runjob 3_ensure_commit _3_ensure_commit - runjob 4_push_branch _4_push_branch - runjob 5_ensure_tag _5_ensure_tag - runjob 6_ensure_release _6_ensure_release - runjob 7_ensure_pr _7_ensure_pr - runjob 8_ensure_assets _8_ensure_assets - runjob 9_upload_assets _9_upload_assets + header '1_ensure_branch' && _1_ensure_branch + header '2_ensure_changelog' && _2_ensure_changelog + header '3_ensure_commit' && _3_ensure_commit + header '4_push_branch' && _4_push_branch + header '5_ensure_tag' && _5_ensure_tag + header '6_ensure_release' && _6_ensure_release + header '7_ensure_pr' && _7_ensure_pr + header '8_ensure_assets' && _8_ensure_assets + header '9_upload_assets' && _9_upload_assets + + COLOR=2 header 'final steps' + cat </dev/null 2>&1; then - sh_c gh release edit \ + release_url="$(sh_c gh release edit \ --draft \ --notes-file "./ci/release/changelogs/$VERSION.md" \ ${PRERELEASE:+--prerelease} \ "--title=$VERSION" \ - "$VERSION" + "$VERSION" | tee /dev/stderr)" return 0 fi - sh_c gh release create \ + release_url="$(sh_c gh release create \ --draft \ --notes-file "./ci/release/changelogs/$VERSION.md" \ ${PRERELEASE:+--prerelease} \ "--title=$VERSION" \ - "$VERSION" + "$VERSION" | tee /dev/stderr)" } _7_ensure_pr() { - pr_url=$(gh pr view "$VERSION" --json=url '--template={{ .url }}' 2>/dev/null || true) + # We do not use gh pr view as that includes closed PRs. + pr_url="$(gh pr list --head "$VERSION" --json=url '--template={{ range . }}{{ .url }}{{end}}')" + body="Will be available at $(gh repo view --json=url '--template={{ .url }}')/releases/tag/$VERSION" if [ -n "$pr_url" ]; then - _echo "PR already exists: $pr_url" + sh_c gh pr edit --body "$body" "$VERSION" return 0 fi - sh_c gh pr create --draft --fill + + pr_url="$(sh_c gh pr create --fill --body "$body" | tee /dev/stderr)" } _8_ensure_assets() { # ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION - _echo TODO + log TODO } _9_upload_assets() { diff --git a/ci/sub b/ci/sub index a4961f772..3412fc4a9 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit a4961f772d1f98bb7a8185a6590ed4346684e392 +Subproject commit 3412fc4a998dd70e5d0de20a9bfb526023b093cc From bebbdefa87c167bf741d3cbb48ac3ce44c11c20a Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 13:38:54 -0800 Subject: [PATCH 05/33] 2022-11-12 01:38:54pm --- ci/release/build.sh | 42 +++++++++++++++++++++++++++++++++++------- ci/release/release.sh | 25 ++++++++++++++++--------- ci/sub | 2 +- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/ci/release/build.sh b/ci/release/build.sh index 8da755f81..13bb69d42 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -3,9 +3,26 @@ set -eu cd -- "$(dirname "$0")/../.." . ./ci/sub/lib.sh +help() { + cat </d2-.tar.gz + +Flags: + +--rebuild: By default build.sh will avoid rebuilding finished assets if they + already exist but if you changed something and need to force rebuild, use + this flag. +--local: By default build.sh uses \$TSTRUCT_MACOS_BUILDER and \$TSTRUCT_LINUX_BUILDER + to build the release archives. It's required for now due to the following + issue: https://github.com/terrastruct/d2/issues/31 + With --local, build.sh will cross compile locally. + warning: This is only for testing purposes, do not use in production! +EOF +} + build() { - OS="$1" - ARCH="$2" BUILD_DIR="$BUILD_DIR/$OS/$ARCH" mkdir -p "$BUILD_DIR/bin" @@ -19,14 +36,25 @@ build() { } main() { + unset FLAG \ + FLAGRAW \ + FLAGARG \ + FLAGSHIFT \ + VERSION \ + REBUILD \ + DEST \ + LOCAL \ VERSION="$(git_describe_ref)" BUILD_DIR="ci/release/build/$VERSION" - - runjob linux-amd64 'OS=linux ARCH=amd64 build linux amd64' & - runjob linux-arm64 'OS=linux ARCH=arm64 build linux arm64' & - runjob macos-amd64 'OS=macos ARCH=amd64 build macos amd64' & - runjob macos-arm64 'OS=macos ARCH=arm64 build macos arm64' & + if [ $# -gt 0 ]; then + flag_errusage "no arguments are accepted" + fi + + runjob linux-amd64 'OS=linux ARCH=amd64 build' & + runjob linux-arm64 'OS=linux ARCH=arm64 build' & + runjob macos-amd64 'OS=macos ARCH=amd64 build' & + runjob macos-arm64 'OS=macos ARCH=arm64 build' & wait_jobs } diff --git a/ci/release/release.sh b/ci/release/release.sh index 6e9a82835..149e53570 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -14,12 +14,13 @@ Flags: --rebuild: Normally the release script will avoid rebuilding release assets if they already exist but if you changed something and need to force rebuild, use this flag. ---pre-release: Pass to mark the release on GitHub as a pre-release. For pre-releases the +--prerelease: Pass to mark the release on GitHub as a pre-release. For pre-releases the version format should include a suffix like v0.0.99-alpha.1 As well, for pre-releases the script will not overwrite changelogs/next.md with changelogs/template.md and instead keep it the same as changelogs/v0.0.99-alpha.1.md. This is because you want to maintain the changelog entries for the eventual final release. +--dryrun: Print the commands that would be ran without executing them. Process: @@ -68,7 +69,8 @@ main() { FLAGSHIFT \ VERSION \ REBUILD \ - PRERELEASE + PRERELEASE \ + DRYRUN while :; do flag_parse "$@" case "$FLAG" in @@ -81,11 +83,16 @@ main() { REBUILD=1 shift "$FLAGSHIFT" ;; - pre-release) + prerelease) flag_noarg PRERELEASE=1 shift "$FLAGSHIFT" ;; + dryrun) + flag_noarg + DRYRUN=1 + shift "$FLAGSHIFT" + ;; '') shift "$FLAGSHIFT" break @@ -113,7 +120,7 @@ main() { header '9_upload_assets' && _9_upload_assets COLOR=2 header 'final steps' - cat <&2 </dev/null 2>&1; then - release_url="$(sh_c gh release edit \ + release_url="$(gh release view "$VERSION" --json=url '--template={{ .url }}' 2>/dev/null || true)" + if [ -n "$release_url" ]; then + sh_c gh release edit \ --draft \ --notes-file "./ci/release/changelogs/$VERSION.md" \ ${PRERELEASE:+--prerelease} \ "--title=$VERSION" \ - "$VERSION" | tee /dev/stderr)" + "$VERSION" | tee /dev/stderr return 0 fi release_url="$(sh_c gh release create \ @@ -192,8 +200,7 @@ _7_ensure_pr() { } _8_ensure_assets() { - # ./ci/release/build.sh ${REBUILD:+--rebuild} $VERSION - log TODO + sh_c ./ci/release/build.sh ${REBUILD:+--rebuild} } _9_upload_assets() { diff --git a/ci/sub b/ci/sub index 3412fc4a9..d95383e2e 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 3412fc4a998dd70e5d0de20a9bfb526023b093cc +Subproject commit d95383e2ed77d82ffc34b8ecd0a90b5cc7b89d97 From ee86426ef2d95c76322579fdda02a3a7c72c2b7a Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 14:19:09 -0800 Subject: [PATCH 06/33] 2022-11-12 02:19:09pm --- ci/release/build.sh | 60 ++++++-- ci/release/template/README.md.sh | 18 ++- ci/release/template/bin/d2 | 0 ci/release/template/lib.sh | 105 -------------- ci/release/template/{ => scripts}/install.sh | 10 +- ci/release/template/scripts/lib.sh | 137 ++++++++++++++++++ .../template/{ => scripts}/uninstall.sh | 7 +- ci/sub | 2 +- 8 files changed, 213 insertions(+), 126 deletions(-) delete mode 100644 ci/release/template/bin/d2 delete mode 100644 ci/release/template/lib.sh rename ci/release/template/{ => scripts}/install.sh (61%) create mode 100644 ci/release/template/scripts/lib.sh rename ci/release/template/{ => scripts}/uninstall.sh (66%) diff --git a/ci/release/build.sh b/ci/release/build.sh index 13bb69d42..68faa6d50 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -7,7 +7,10 @@ help() { cat </d2-.tar.gz +$0 builds D2 release archives into ./ci/release/build//d2-.tar.gz + +The version is detected via git describe which will use the git tag for the current +commit if available. Flags: @@ -23,16 +26,22 @@ EOF } build() { - BUILD_DIR="$BUILD_DIR/$OS/$ARCH" + HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION" - mkdir -p "$BUILD_DIR/bin" - sh_c cp LICENSE.txt "$BUILD_DIR" - sh_c "./ci/release/template/README.md.sh > $BUILD_DIR" + sh_c mkdir -p "$HW_BUILD_DIR" + sh_c rsync --recursive --perms --delete \ + --human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/" + VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'" + sh_c rm -f "$HW_BUILD_DIR/README.md.sh" + sh_c find "$HW_BUILD_DIR" -exec touch {} \; export GOOS=$(goos "$OS") export GOARCH="$ARCH" - sh_c go build -ldflags "-X lib/version.Version=$VERSION" \ - -o "$BUILD_DIR/bin/d2" ./cmd/d2 + sh_c mkdir -p "$HW_BUILD_DIR/bin" + sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \ + -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 + + sh_c tar czf "$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" "$HW_BUILD_DIR" } main() { @@ -41,11 +50,44 @@ main() { FLAGARG \ FLAGSHIFT \ VERSION \ + BUILD_DIR \ + HW_BUILD_DIR \ REBUILD \ - DEST \ LOCAL \ + DRYRUN VERSION="$(git_describe_ref)" BUILD_DIR="ci/release/build/$VERSION" + while :; do + flag_parse "$@" + case "$FLAG" in + h|help) + help + return 0 + ;; + rebuild) + flag_noarg + REBUILD=1 + shift "$FLAGSHIFT" + ;; + local) + flag_noarg + LOCAL=1 + shift "$FLAGSHIFT" + ;; + dryrun) + flag_noarg + DRYRUN=1 + shift "$FLAGSHIFT" + ;; + '') + shift "$FLAGSHIFT" + break + ;; + *) + flag_errusage "unrecognized flag $FLAGRAW" + ;; + esac + done if [ $# -gt 0 ]; then flag_errusage "no arguments are accepted" @@ -55,7 +97,7 @@ main() { runjob linux-arm64 'OS=linux ARCH=arm64 build' & runjob macos-amd64 'OS=macos ARCH=amd64 build' & runjob macos-arm64 'OS=macos ARCH=arm64 build' & - wait_jobs + waitjobs } main "$@" diff --git a/ci/release/template/README.md.sh b/ci/release/template/README.md.sh index 4f4b2e082..84a0c01c2 100755 --- a/ci/release/template/README.md.sh +++ b/ci/release/template/README.md.sh @@ -4,11 +4,23 @@ set -eu cat <&2 -} - -printferr() { - COLOR=1 printfp err "$@" >&2 -} - -sh_c() { - COLOR=3 echop exec "$*" - "$@" -} - -get_rand_color() { - # 1-6 are regular and 9-14 are bright. - # 1,2 and 9,10 are red and green but we use those for success and failure. - pick "$*" 3 4 5 6 11 12 13 14 -} - -echop() {( - prefix="$1" - shift - - if [ -z "${COLOR:-}" ]; then - COLOR="$(get_rand_color "$prefix")" - fi - printf '%s: %s\n' "$(setaf "$COLOR" "$prefix")" "$*" -)} - -printfp() {( - PREFIX="$1" - shift - echop "$PREFIX" "$(printf "$@")" -)} - -hide() { - out="$(mktemp)" - set +e - "$@" >"$out" 2>&1 - code="$?" - set -e - if [ "$code" -eq 0 ]; then - return - fi - cat "$out" >&2 - exit "$code" -} - -echo_dur() { - local dur=$1 - local h=$((dur/60/60)) - local m=$((dur/60%60)) - local s=$((dur%60)) - printf '%dh%dm%ds' "$h" "$m" "$s" -} - -sponge() { - dst="$1" - tmp="$(mktemp)" - cat > "$tmp" - cat "$tmp" > "$dst" -} - -stripansi() { - # First regex gets rid of standard xterm escape sequences for controlling - # visual attributes. - # The second regex I'm not 100% sure, the reference says it selects the US - # encoding but I'm not sure why that's necessary or why it always occurs - # in tput sgr0 before the standard escape sequence. - # See tput sgr0 | xxd - sed -e $'s/\x1b\[[0-9;]*m//g' -e $'s/\x1b(.//g' -} - -runtty() { - case "$(uname)" in - Darwin) - script -q /dev/null "$@" - ;; - Linux) - script -eqc "$*" - ;; - *) - echoerr "runtty: unsupported OS $(uname)" - esac -} diff --git a/ci/release/template/install.sh b/ci/release/template/scripts/install.sh similarity index 61% rename from ci/release/template/install.sh rename to ci/release/template/scripts/install.sh index 57207357a..eff495049 100755 --- a/ci/release/template/install.sh +++ b/ci/release/template/scripts/install.sh @@ -1,15 +1,15 @@ #!/bin/sh set -eu -. "$(dirname "$0")/lib.sh" +cd -- "$(dirname "$0")/.." +. ./scripts/lib.sh main() { - if [ ! -e "${PREFIX:-}" ]; then + if [ ! -e "${PREFIX-}" ]; then echoerr "\$PREFIX must be set to a unix prefix directory in which to install d2 like /usr/local" - exit 1 + return 1 fi - mkdir -p "$PREFIX" - + sh_c mkdir -p "$PREFIX" sh_c install ./bin/d2 "$PREFIX/bin/d2" } diff --git a/ci/release/template/scripts/lib.sh b/ci/release/template/scripts/lib.sh new file mode 100644 index 000000000..074eb3a91 --- /dev/null +++ b/ci/release/template/scripts/lib.sh @@ -0,0 +1,137 @@ +#!/bin/sh + +rand() { + seed="$1" + range="$2" + + seed_file="$(mktemp)" + _echo "$seed" | md5sum > "$seed_file" + shuf -i "$range" -n 1 --random-source="$seed_file" +} + +pick() { + seed="$1" + shift + i="$(rand "$seed" "1-$#")" + eval "_echo \"\$$i\"" +} + +tput() { + if [ -n "$TERM" ]; then + command tput "$@" + fi +} + +setaf() { + tput setaf "$1" + shift + printf '%s' "$*" + tput sgr0 +} + +_echo() { + printf '%s\n' "$*" +} + +get_rand_color() { + # 1-6 are regular and 9-14 are bright. + # 1,2 and 9,10 are red and green but we use those for success and failure. + pick "$*" 3 4 5 6 11 12 13 14 +} + +echop() { + prefix="$1" + shift + + if [ "$#" -gt 0 ]; then + printfp "$prefix" "%s\n" "$*" + else + printfp "$prefix" + printf '\n' + fi +} + +printfp() {( + prefix="$1" + shift + + if [ -z "${COLOR:-}" ]; then + COLOR="$(get_rand_color "$prefix")" + fi + printf '%s' "$(setaf "$COLOR" "$prefix")" + + if [ $# -gt 0 ]; then + printf ': ' + printf "$@" + fi +)} + +catp() { + prefix="$1" + shift + + printfp "$prefix" + printf ': ' + read -r line + _echo "$line" + + indent=$(repeat ' ' 2) + sed "s/^/$indent/" +} + +repeat() { + char="$1" + times="$2" + seq -s "$char" "$times" | tr -d '[:digit:]' +} + +strlen() { + printf %s "$1" | wc -c +} + +echoerr() { + COLOR=1 echop err "$*" >&2 +} + +caterr() { + COLOR=1 catp err "$@" >&2 +} + +printferr() { + COLOR=1 printfp err "$@" >&2 +} + +logp() { + echop "$@" >&2 +} + +logfp() { + printfp "$@" >&2 +} + +logpcat() { + catp "$@" >&2 +} + +log() { + COLOR=5 logp log "$@" +} + +logf() { + COLOR=5 logfp log "$@" +} + +logcat() { + COLOR=5 catp log "$@" >&2 +} + +sh_c() { + COLOR=3 logp exec "$*" + if [ -z "${DRYRUN-}" ]; then + "$@" + fi +} + +header() { + logp "/* $1 */" +} diff --git a/ci/release/template/uninstall.sh b/ci/release/template/scripts/uninstall.sh similarity index 66% rename from ci/release/template/uninstall.sh rename to ci/release/template/scripts/uninstall.sh index 2ec6a47c1..d6d891dca 100755 --- a/ci/release/template/uninstall.sh +++ b/ci/release/template/scripts/uninstall.sh @@ -1,11 +1,12 @@ #!/bin/sh set -eu -. "$(dirname "$0")/lib.sh" +cd -- "$(dirname "$0")/.." +. ./scripts/lib.sh main() { - if [ ! -e "${PREFIX:-}" ]; then + if [ ! -e "${PREFIX-}" ]; then echoerr "\$PREFIX must be set to a unix prefix directory from which to uninstall d2 like /usr/local" - exit 1 + return 1 fi sh_c rm -f "$PREFIX/bin/d2" diff --git a/ci/sub b/ci/sub index d95383e2e..4760501f6 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit d95383e2ed77d82ffc34b8ecd0a90b5cc7b89d97 +Subproject commit 4760501f65c5abace1790a501f34a7b1e3223b2f From b88cd7edb3e3594a6d0e34c7cb91cc68653ca6a1 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 14:23:18 -0800 Subject: [PATCH 07/33] 2022-11-12 02:23:18pm --- ci/release/release.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/release/release.sh b/ci/release/release.sh index 149e53570..df9e9be7c 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -171,12 +171,12 @@ _5_ensure_tag() { _6_ensure_release() { release_url="$(gh release view "$VERSION" --json=url '--template={{ .url }}' 2>/dev/null || true)" if [ -n "$release_url" ]; then - sh_c gh release edit \ + release_url="$(sh_c gh release edit \ --draft \ --notes-file "./ci/release/changelogs/$VERSION.md" \ ${PRERELEASE:+--prerelease} \ "--title=$VERSION" \ - "$VERSION" | tee /dev/stderr + "$VERSION" | tee /dev/stderr)" return 0 fi release_url="$(sh_c gh release create \ From 3c9e953c41f126169f122c5983c5898e974af9cf Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 17:12:41 -0800 Subject: [PATCH 08/33] 2022-11-12 05:12:41pm --- ci/release/build.sh | 20 +++++-- ci/release/builders/init_aws.sh | 98 +++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 6 deletions(-) create mode 100755 ci/release/builders/init_aws.sh diff --git a/ci/release/build.sh b/ci/release/build.sh index 68faa6d50..3ddbd47de 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -5,7 +5,7 @@ cd -- "$(dirname "$0")/../.." help() { cat </d2-.tar.gz @@ -17,9 +17,10 @@ Flags: --rebuild: By default build.sh will avoid rebuilding finished assets if they already exist but if you changed something and need to force rebuild, use this flag. ---local: By default build.sh uses \$TSTRUCT_MACOS_BUILDER and \$TSTRUCT_LINUX_BUILDER - to build the release archives. It's required for now due to the following - issue: https://github.com/terrastruct/d2/issues/31 +--local: By default build.sh uses \$TSTRUCT_MACOS_AMD64_BUILDER, + \$TSTRUCT_MACOS_ARM64_BUILDER, \$TSTRUCT_LINUX_AMD64_BUILDER and + \$TSTRUCT_LINUX_ARM64_BUILDER to build the release archives. It's required for + now due to the following issue: https://github.com/terrastruct/d2/issues/31 With --local, build.sh will cross compile locally. warning: This is only for testing purposes, do not use in production! EOF @@ -27,6 +28,12 @@ EOF build() { HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION" + ARCHIVE="$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" + + if [ -e "$ARCHIVE" -a -z "${REBUILD-}" ]; then + log "skipping as already built at $ARCHIVE" + return 0 + fi sh_c mkdir -p "$HW_BUILD_DIR" sh_c rsync --recursive --perms --delete \ @@ -41,7 +48,7 @@ build() { sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \ -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 - sh_c tar czf "$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" "$HW_BUILD_DIR" + sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR" } main() { @@ -54,7 +61,8 @@ main() { HW_BUILD_DIR \ REBUILD \ LOCAL \ - DRYRUN + DRYRUN \ + ARCHIVE VERSION="$(git_describe_ref)" BUILD_DIR="ci/release/build/$VERSION" while :; do diff --git a/ci/release/builders/init_aws.sh b/ci/release/builders/init_aws.sh new file mode 100755 index 000000000..0f85ddfec --- /dev/null +++ b/ci/release/builders/init_aws.sh @@ -0,0 +1,98 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../../.." +. ./ci/sub/lib.sh + +help() { + cat </dev/null \ + | jq -r .SecurityGroups[0].GroupId) + if [ -z "$SG_ID" ]; then + SG_ID=$(sh_c aws ec2 create-security-group \ + --group-name ssh \ + --description ssh \ + --vpc-id "$VPC_ID" | jq -r .GroupId) + fi + + header security-group-ingress + SG_RULES_COUNT=$(aws ec2 describe-security-groups --group-names ssh \ + | jq -r '.SecurityGroups[0].IpPermissions | length') + if [ "$SG_RULES_COUNT" -eq 0 ]; then + sh_c aws ec2 authorize-security-group-ingress \ + --group-id "$SG_ID" \ + --protocol tcp \ + --port 22 \ + --cidr 0.0.0.0/0 >/dev/null + fi + + header linux-amd64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-linux-amd64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0d593311db5abb72b \ + --count=1 \ + --instance-type=t2.micro \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \ + 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null + fi + + header linux-arm64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-linux-arm64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0efabcf945ffd8831 \ + --count=1 \ + --instance-type=t4g.nano \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \ + 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null + fi +} + +main "$@" From 590a1bc00043b9809c840e08e83753f1bcd7a1d4 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 19:10:45 -0800 Subject: [PATCH 09/33] 2022-11-12 07:10:45pm --- ci/release/_build.sh | 19 ++++++ ci/release/build.sh | 81 +++++++++++++++++-------- ci/release/build_docker.sh | 19 ++++++ ci/release/builders/Dockerfile | 11 ++++ ci/release/builders/create_aws.sh | 98 +++++++++++++++++++++++++++++++ ci/release/builders/init_aws.sh | 62 ++++--------------- ci/sub | 2 +- 7 files changed, 216 insertions(+), 76 deletions(-) create mode 100755 ci/release/_build.sh create mode 100755 ci/release/build_docker.sh create mode 100644 ci/release/builders/Dockerfile create mode 100755 ci/release/builders/create_aws.sh diff --git a/ci/release/_build.sh b/ci/release/_build.sh new file mode 100755 index 000000000..d30527b0c --- /dev/null +++ b/ci/release/_build.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh + +sh_c mkdir -p "$HW_BUILD_DIR" +sh_c rsync --recursive --perms --delete \ + --human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/" +VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'" +sh_c rm -f "$HW_BUILD_DIR/README.md.sh" +sh_c find "$HW_BUILD_DIR" -exec touch {} \; + +export GOOS=$(goos "$OS") +export GOARCH="$ARCH" +sh_c mkdir -p "$HW_BUILD_DIR/bin" +sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \ + -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 + +sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR" diff --git a/ci/release/build.sh b/ci/release/build.sh index 3ddbd47de..f944e08e7 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -26,31 +26,6 @@ Flags: EOF } -build() { - HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION" - ARCHIVE="$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" - - if [ -e "$ARCHIVE" -a -z "${REBUILD-}" ]; then - log "skipping as already built at $ARCHIVE" - return 0 - fi - - sh_c mkdir -p "$HW_BUILD_DIR" - sh_c rsync --recursive --perms --delete \ - --human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/" - VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'" - sh_c rm -f "$HW_BUILD_DIR/README.md.sh" - sh_c find "$HW_BUILD_DIR" -exec touch {} \; - - export GOOS=$(goos "$OS") - export GOARCH="$ARCH" - sh_c mkdir -p "$HW_BUILD_DIR/bin" - sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \ - -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 - - sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR" -} - main() { unset FLAG \ FLAGRAW \ @@ -108,4 +83,60 @@ main() { waitjobs } +build() { + HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION" + ARCHIVE="$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" + + if [ -e "$ARCHIVE" -a -z "${REBUILD-}" ]; then + log "skipping as already built at $ARCHIVE" + return 0 + fi + + case $OS in + # macos) + # ;; + linux) + case $ARCH in + amd64) + RHOST=$TSTRUCT_LINUX_AMD64_BUILDER build_rhost + ;; + arm64) + RHOST=$TSTRUCT_LINUX_ARM64_BUILDER build_rhost + ;; + *) + COLOR=3 logp warn "no builder for OS=$OS, building locally..." + build_local + ;; + esac + ;; + *) + COLOR=3 logp warn "no builder for OS=$OS, building locally..." + # build_local + ;; + esac +} + +build_local() { + export DRYRUN \ + HW_BUILD_DIR \ + VERSION \ + OS \ + ARCH \ + ARCHIVE + sh_c ./ci/release/_build.sh +} + +build_rhost() { + sh_c ssh "$RHOST" mkdir -p src + sh_c rsync --archive --human-readable --delete ./ "$RHOST:src/d2/" + sh_c ssh -tttt "$RHOST" "DRYRUN=${DRYRUN-} \ +HW_BUILD_DIR=$HW_BUILD_DIR \ +VERSION=$VERSION \ +OS=$OS \ +ARCH=$ARCH \ +ARCHIVE=$ARCHIVE \ +./src/d2/ci/release/build_docker.sh" + sh_c rsync --archive --human-readable "$RHOST:src/d2/$ARCHIVE" "$ARCHIVE" +} + main "$@" diff --git a/ci/release/build_docker.sh b/ci/release/build_docker.sh new file mode 100755 index 000000000..f5505b7b7 --- /dev/null +++ b/ci/release/build_docker.sh @@ -0,0 +1,19 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh + +tag="$(sh_c docker build \ + -qf ./ci/release/builders/Dockerfile ./ci/release/builders )" +sh_c docker run -it --rm \ + -v "$HOME:$HOME" \ + -u "$(id -u):$(id -g)" \ + -w "$HOME" \ + -e DRYRUN="${DRYRUN-}" \ + -e HW_BUILD_DIR="$HW_BUILD_DIR" \ + -e VERSION="$VERSION" \ + -e OS="$OS" \ + -e ARCH="$ARCH" \ + -e ARCHIVE="$ARCHIVE" \ + -e TERM="$TERM" \ + "$tag" ./src/d2/ci/release/_build.sh diff --git a/ci/release/builders/Dockerfile b/ci/release/builders/Dockerfile new file mode 100644 index 000000000..59dd7f86c --- /dev/null +++ b/ci/release/builders/Dockerfile @@ -0,0 +1,11 @@ +FROM centos:7 + +ARG GOVERSION=1.19.3 + +RUN curl -fsSL "https://go.dev/dl/go$GOVERSION.linux-amd64.tar.gz" >/tmp/go.tar.gz +RUN tar -C /usr/local -xzf /tmp/go.tar.gz + +ENV PATH="/usr/local/go/bin:$PATH" + +RUN yum install -y rsync +RUN yum groupinstall -y 'Development Tools' diff --git a/ci/release/builders/create_aws.sh b/ci/release/builders/create_aws.sh new file mode 100755 index 000000000..4d71dc339 --- /dev/null +++ b/ci/release/builders/create_aws.sh @@ -0,0 +1,98 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../../.." +. ./ci/sub/lib.sh + +help() { + cat </dev/null \ + | jq -r .SecurityGroups[0].GroupId) + if [ -z "$SG_ID" ]; then + SG_ID=$(sh_c aws ec2 create-security-group \ + --group-name ssh \ + --description ssh \ + --vpc-id "$VPC_ID" | jq -r .GroupId) + fi + + header security-group-ingress + SG_RULES_COUNT=$(aws ec2 describe-security-groups --group-names ssh \ + | jq -r '.SecurityGroups[0].IpPermissions | length') + if [ "$SG_RULES_COUNT" -eq 0 ]; then + sh_c aws ec2 authorize-security-group-ingress \ + --group-id "$SG_ID" \ + --protocol tcp \ + --port 22 \ + --cidr 0.0.0.0/0 >/dev/null + fi + + header linux-amd64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-linux-amd64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0d593311db5abb72b \ + --count=1 \ + --instance-type=t2.micro \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \ + 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null + fi + + header linux-arm64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-linux-arm64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0efabcf945ffd8831 \ + --count=1 \ + --instance-type=t4g.nano \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \ + 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null + fi +} + +main "$@" diff --git a/ci/release/builders/init_aws.sh b/ci/release/builders/init_aws.sh index 0f85ddfec..34c54f4cd 100755 --- a/ci/release/builders/init_aws.sh +++ b/ci/release/builders/init_aws.sh @@ -7,7 +7,7 @@ help() { cat </dev/null \ - | jq -r .SecurityGroups[0].GroupId) - if [ -z "$SG_ID" ]; then - SG_ID=$(sh_c aws ec2 create-security-group \ - --group-name ssh \ - --description ssh \ - --vpc-id "$VPC_ID" | jq -r .GroupId) - fi - - header security-group-ingress - SG_RULES_COUNT=$(aws ec2 describe-security-groups --group-names ssh \ - | jq -r '.SecurityGroups[0].IpPermissions | length') - if [ "$SG_RULES_COUNT" -eq 0 ]; then - sh_c aws ec2 authorize-security-group-ingress \ - --group-id "$SG_ID" \ - --protocol tcp \ - --port 22 \ - --cidr 0.0.0.0/0 >/dev/null - fi - header linux-amd64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-linux-amd64; then - sh_c aws ec2 run-instances \ - --image-id=ami-0d593311db5abb72b \ - --count=1 \ - --instance-type=t2.micro \ - --security-groups=ssh \ - "--key-name=$KEY_NAME" \ - --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \ - 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null - fi - + # RHOST=$TSTRUCT_LINUX_AMD64_BUILDER init_rhost header linux-arm64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-linux-arm64; then - sh_c aws ec2 run-instances \ - --image-id=ami-0efabcf945ffd8831 \ - --count=1 \ - --instance-type=t4g.nano \ - --security-groups=ssh \ - "--key-name=$KEY_NAME" \ - --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \ - 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null - fi + RHOST=$TSTRUCT_LINUX_ARM64_BUILDER init_rhost +} + +init_rhost() { + sh_c ssh "$RHOST" 'sudo yum upgrade -y' + sh_c ssh "$RHOST" 'sudo yum install -y docker' + sh_c ssh "$RHOST" 'sudo systemctl start docker' + sh_c ssh "$RHOST" 'sudo systemctl enable docker' + sh_c ssh "$RHOST" 'sudo usermod -a -G docker ec2-user' + sh_c ssh "$RHOST" 'sudo reboot' || true } main "$@" diff --git a/ci/sub b/ci/sub index 4760501f6..7ede128e7 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 4760501f65c5abace1790a501f34a7b1e3223b2f +Subproject commit 7ede128e71f0409b61dd9088aea22389f1b7b221 From 016c7373882e0e5a1321369b61dacb22a4ad8527 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 19:36:56 -0800 Subject: [PATCH 10/33] 2022-11-12 07:36:56pm --- ci/release/build_docker.sh | 2 ++ ci/release/builders/Dockerfile | 4 ++-- ci/release/builders/create_aws.sh | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ci/release/build_docker.sh b/ci/release/build_docker.sh index f5505b7b7..88aacac87 100755 --- a/ci/release/build_docker.sh +++ b/ci/release/build_docker.sh @@ -4,6 +4,7 @@ cd -- "$(dirname "$0")/../.." . ./ci/sub/lib.sh tag="$(sh_c docker build \ + --build-arg GOVERSION="1.19.3.linux-$ARCH" \ -qf ./ci/release/builders/Dockerfile ./ci/release/builders )" sh_c docker run -it --rm \ -v "$HOME:$HOME" \ @@ -16,4 +17,5 @@ sh_c docker run -it --rm \ -e ARCH="$ARCH" \ -e ARCHIVE="$ARCHIVE" \ -e TERM="$TERM" \ + -e HOME="$HOME" \ "$tag" ./src/d2/ci/release/_build.sh diff --git a/ci/release/builders/Dockerfile b/ci/release/builders/Dockerfile index 59dd7f86c..c3d3cc22e 100644 --- a/ci/release/builders/Dockerfile +++ b/ci/release/builders/Dockerfile @@ -1,8 +1,8 @@ FROM centos:7 -ARG GOVERSION=1.19.3 +ARG GOVERSION= -RUN curl -fsSL "https://go.dev/dl/go$GOVERSION.linux-amd64.tar.gz" >/tmp/go.tar.gz +RUN curl -fsSL "https://go.dev/dl/go$GOVERSION.tar.gz" >/tmp/go.tar.gz RUN tar -C /usr/local -xzf /tmp/go.tar.gz ENV PATH="/usr/local/go/bin:$PATH" diff --git a/ci/release/builders/create_aws.sh b/ci/release/builders/create_aws.sh index 4d71dc339..dc9eee94c 100755 --- a/ci/release/builders/create_aws.sh +++ b/ci/release/builders/create_aws.sh @@ -79,6 +79,16 @@ create_aws() { --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \ 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null fi + while true; do + dnsname=$(sh_c aws ec2 describe-instances \ + --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-amd64' \ + | jq -r '.Reservations[].Instances[].PublicDnsName') + if [ -n "$dnsname" ]; then + log "TSTRUCT_LINUX_AMD64_BUILDER=$dnsname" + break + fi + sleep 5 + done header linux-arm64 if ! aws ec2 describe-instances \ @@ -93,6 +103,16 @@ create_aws() { --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \ 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null fi + while true; do + dnsname=$(sh_c aws ec2 describe-instances \ + --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-arm64' \ + | jq -r '.Reservations[].Instances[].PublicDnsName') + if [ -n "$dnsname" ]; then + log "TSTRUCT_LINUX_AMD64_BUILDER=$dnsname" + break + fi + sleep 5 + done } main "$@" From 8606c427fbbadbeffe1c8f9ae1719d512090f895 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 19:42:39 -0800 Subject: [PATCH 11/33] 2022-11-12 07:42:39pm --- ci/release/build.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ci/release/build.sh b/ci/release/build.sh index f944e08e7..7a8420f89 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -92,6 +92,11 @@ build() { return 0 fi + if [ -n "${LOCAL-}" ]; then + build_local + return 0 + fi + case $OS in # macos) # ;; @@ -111,7 +116,7 @@ build() { ;; *) COLOR=3 logp warn "no builder for OS=$OS, building locally..." - # build_local + build_local ;; esac } From 935251e8acd4b7638c906bd9cf47648f42204460 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 20:39:14 -0800 Subject: [PATCH 12/33] 2022-11-12 08:39:14pm --- ci/release/builders/Dockerfile | 11 ++-- ci/release/builders/Dockerfile-centos | 16 +++++ .../builders/{create_aws.sh => ensure_aws.sh} | 39 +++++++++--- ci/release/builders/init_aws.sh | 60 ------------------- 4 files changed, 54 insertions(+), 72 deletions(-) create mode 100644 ci/release/builders/Dockerfile-centos rename ci/release/builders/{create_aws.sh => ensure_aws.sh} (76%) delete mode 100755 ci/release/builders/init_aws.sh diff --git a/ci/release/builders/Dockerfile b/ci/release/builders/Dockerfile index c3d3cc22e..5adc0bd25 100644 --- a/ci/release/builders/Dockerfile +++ b/ci/release/builders/Dockerfile @@ -1,11 +1,12 @@ -FROM centos:7 +FROM debian:10 + +RUN apt-get update +RUN apt-get install -y curl ARG GOVERSION= - RUN curl -fsSL "https://go.dev/dl/go$GOVERSION.tar.gz" >/tmp/go.tar.gz RUN tar -C /usr/local -xzf /tmp/go.tar.gz - ENV PATH="/usr/local/go/bin:$PATH" -RUN yum install -y rsync -RUN yum groupinstall -y 'Development Tools' +RUN apt-get install -y build-essential +RUN apt-get install -y rsync diff --git a/ci/release/builders/Dockerfile-centos b/ci/release/builders/Dockerfile-centos new file mode 100644 index 000000000..66aaf6f17 --- /dev/null +++ b/ci/release/builders/Dockerfile-centos @@ -0,0 +1,16 @@ +FROM centos:7 + +ARG GOVERSION= + +RUN curl -fsSL "https://go.dev/dl/go$GOVERSION.tar.gz" >/tmp/go.tar.gz +RUN tar -C /usr/local -xzf /tmp/go.tar.gz + +ENV PATH="/usr/local/go/bin:$PATH" + +RUN yum install -y rsync wget +RUN yum groupinstall -y 'Development Tools' + +RUN curl -fsSL https://ftp.gnu.org/gnu/gcc/gcc-5.2.0/gcc-5.2.0.tar.gz >/tmp/gcc.tar.gz +RUN tar -C /usr/local -xzf /tmp/gcc.tar.gz +RUN cd /usr/local/gcc-5.2.0 && ./contrib/download_prerequisites && mkdir -p build \ + && cd build && ../configure --disable-multilib && make && make install diff --git a/ci/release/builders/create_aws.sh b/ci/release/builders/ensure_aws.sh similarity index 76% rename from ci/release/builders/create_aws.sh rename to ci/release/builders/ensure_aws.sh index dc9eee94c..8b7615e7c 100755 --- a/ci/release/builders/create_aws.sh +++ b/ci/release/builders/ensure_aws.sh @@ -7,7 +7,7 @@ help() { cat < Date: Sat, 12 Nov 2022 21:07:11 -0800 Subject: [PATCH 13/33] 2022-11-12 09:07:11pm --- ci/release/builders/ensure_aws.sh | 2 ++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ci/release/builders/ensure_aws.sh b/ci/release/builders/ensure_aws.sh index 8b7615e7c..5f2aede0e 100755 --- a/ci/release/builders/ensure_aws.sh +++ b/ci/release/builders/ensure_aws.sh @@ -123,6 +123,8 @@ init_rhosts() { RHOST=$TSTRUCT_LINUX_AMD64_BUILDER init_rhost header linux-arm64 RHOST=$TSTRUCT_LINUX_ARM64_BUILDER init_rhost + log "export TSTRUCT_LINUX_AMD64_BUILDER=$TSTRUCT_LINUX_AMD64_BUILDER" + log "export TSTRUCT_LINUX_ARM64_BUILDER=$TSTRUCT_LINUX_ARM64_BUILDER" } init_rhost() { diff --git a/go.mod b/go.mod index 0977ac236..f0c96a553 100644 --- a/go.mod +++ b/go.mod @@ -28,7 +28,7 @@ require ( oss.terrastruct.com/xjson v0.0.0-20221018000420-4986731c4c4a oss.terrastruct.com/xos v0.0.0-20221018030138-c96e7ae96e5d oss.terrastruct.com/xrand v0.0.0-20221020211818-4ac08e618333 - rogchap.com/v8go v0.7.0 + rogchap.com/v8go v0.7.1-0.20221102201510-1f00b5007d95 ) require ( diff --git a/go.sum b/go.sum index b27d23c8d..ac8c2599d 100644 --- a/go.sum +++ b/go.sum @@ -786,8 +786,8 @@ oss.terrastruct.com/xos v0.0.0-20221018030138-c96e7ae96e5d h1:rrPTkbAfsRTW1WLoTz oss.terrastruct.com/xos v0.0.0-20221018030138-c96e7ae96e5d/go.mod h1:uSONPDInIwglnC+0zYs8YOjiUD8ZUSnqDTTI82j7Oro= oss.terrastruct.com/xrand v0.0.0-20221020211818-4ac08e618333 h1:7EdxwXM75Id1VIN71QbE8bLzZRMs0qD7olnDw5gbI7w= oss.terrastruct.com/xrand v0.0.0-20221020211818-4ac08e618333/go.mod h1:O7TAoBmlQhoi46RdgVikDcoLRb/vLflhkXCAd+nO4SM= -rogchap.com/v8go v0.7.0 h1:kgjbiO4zE5itA962ze6Hqmbs4HgZbGzmueCXsZtremg= -rogchap.com/v8go v0.7.0/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs= +rogchap.com/v8go v0.7.1-0.20221102201510-1f00b5007d95 h1:r89YHVIWeQj/A3Nu6462eqARUECJlJkLRk36pfML1xA= +rogchap.com/v8go v0.7.1-0.20221102201510-1f00b5007d95/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= From 0cd0bdc96acb508805c280add4c71433ca0d7356 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sat, 12 Nov 2022 21:15:56 -0800 Subject: [PATCH 14/33] 2022-11-12 09:15:56pm --- ci/sub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/sub b/ci/sub index 7ede128e7..3be3f2345 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 7ede128e71f0409b61dd9088aea22389f1b7b221 +Subproject commit 3be3f2345e3cd75f2570afdcebfdf2d3732e5dda From d8b54c2e4251b3ad8d9ead3fb0c36ec1c61b9eaa Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sun, 13 Nov 2022 16:57:47 -0800 Subject: [PATCH 15/33] ci/release: Full docs --- ci/release/README.md | 46 ++++++++++++++++++++++++++++++++++++++- ci/release/_install.sh | 5 +++++ ci/release/build.sh | 15 ++++--------- ci/release/gen_install.sh | 2 ++ ci/release/release.sh | 8 ------- ci/sub | 2 +- 6 files changed, 57 insertions(+), 21 deletions(-) create mode 100755 ci/release/_install.sh create mode 100755 ci/release/gen_install.sh diff --git a/ci/release/README.md b/ci/release/README.md index af207b18d..8833ecd0e 100644 --- a/ci/release/README.md +++ b/ci/release/README.md @@ -1,3 +1,47 @@ # release -Run `./release.sh --help` for instructions. +## _install.sh + +The template for the install script in the root of the repository. + +### gen_install.sh + +Generates the install.sh script in the root of the repository by prepending the libraries +it depends on from ../sub/lib. + +## release.sh + +- ./release.sh is the top level script to generate a new release. + Run with --help for usage. + +## build.sh + +- ./build.sh builds the release archives for each platform into ./build//*.tar.gz + Run with --help for usage. + +> note: Remember for production releases you need to set the $TSTRUCT_OS_ARCH_BUILDER +> variables as we must compile d2 directly on each release target to include dagre. +> See https://github.com/terrastruct/d2/issues/31 + +### build_docker.sh + +Helper script called by build.sh to build D2 on each linux runner inside Docker. +The Dockerfile is in ./builders/Dockerfile + +### _build.sh + +Called by build.sh (with --local or macOS) or build_docker.sh (on linux) to create the +release archive. + +Do not invoke directly. If you want to produce a build for a single platform run build.sh +as so: + +```sh + # To only build the linux-amd64 release. +./build.sh --run=linux-amd64 +``` + +```sh + # To only build the linux-amd64 release locally. +./build.sh --local --run=linux-amd64 +``` diff --git a/ci/release/_install.sh b/ci/release/_install.sh new file mode 100755 index 000000000..6f4f2d794 --- /dev/null +++ b/ci/release/_install.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu + +$LOG_SH +$RAND_SH diff --git a/ci/release/build.sh b/ci/release/build.sh index 7a8420f89..34570ed52 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -27,17 +27,6 @@ EOF } main() { - unset FLAG \ - FLAGRAW \ - FLAGARG \ - FLAGSHIFT \ - VERSION \ - BUILD_DIR \ - HW_BUILD_DIR \ - REBUILD \ - LOCAL \ - DRYRUN \ - ARCHIVE VERSION="$(git_describe_ref)" BUILD_DIR="ci/release/build/$VERSION" while :; do @@ -62,6 +51,10 @@ main() { DRYRUN=1 shift "$FLAGSHIFT" ;; + run) + flag_reqarg + JOB_FILTER="$FLAGARG" + shift "$FLAGSHIFT" '') shift "$FLAGSHIFT" break diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh new file mode 100755 index 000000000..92b70ea0d --- /dev/null +++ b/ci/release/gen_install.sh @@ -0,0 +1,2 @@ +#!/bin/sh +set -eu diff --git a/ci/release/release.sh b/ci/release/release.sh index df9e9be7c..a87b7f37e 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -63,14 +63,6 @@ EOF } main() { - unset FLAG \ - FLAGRAW \ - FLAGARG \ - FLAGSHIFT \ - VERSION \ - REBUILD \ - PRERELEASE \ - DRYRUN while :; do flag_parse "$@" case "$FLAG" in diff --git a/ci/sub b/ci/sub index 3be3f2345..5d23dec92 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 3be3f2345e3cd75f2570afdcebfdf2d3732e5dda +Subproject commit 5d23dec92cee36692bc8c8cece74890cce9631e4 From 9989816b4b23b9ee7910e6932797faadec24a367 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sun, 13 Nov 2022 17:12:24 -0800 Subject: [PATCH 16/33] ci: Implement gen_install.sh --- ci/release/gen_install.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index 92b70ea0d..314b468d1 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -1,2 +1,33 @@ #!/bin/sh set -eu +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh + +cat >./install.sh <> ./install.sh From 408a78d48a417986aef9aa56f7b75af085606d4b Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sun, 13 Nov 2022 21:58:55 -0800 Subject: [PATCH 17/33] ci/release: Many fixes --- ci/release/_build.sh | 4 +- ci/release/_install.sh | 8 +- ci/release/build.sh | 16 +- ci/release/build_docker.sh | 22 +- ci/release/builders/ensure_aws.sh | 3 +- ci/release/gen_install.sh | 6 +- ci/release/release.sh | 9 +- ci/sub | 2 +- install.sh | 350 ++++++++++++++++++++++++++++++ 9 files changed, 383 insertions(+), 37 deletions(-) create mode 100644 install.sh diff --git a/ci/release/_build.sh b/ci/release/_build.sh index d30527b0c..db1b27de9 100755 --- a/ci/release/_build.sh +++ b/ci/release/_build.sh @@ -8,12 +8,12 @@ sh_c rsync --recursive --perms --delete \ --human-readable --copy-links ./ci/release/template/ "$HW_BUILD_DIR/" VERSION=$VERSION sh_c eval "'$HW_BUILD_DIR/README.md.sh'" \> "'$HW_BUILD_DIR/README.md'" sh_c rm -f "$HW_BUILD_DIR/README.md.sh" -sh_c find "$HW_BUILD_DIR" -exec touch {} \; +sh_c find "$HW_BUILD_DIR" -exec touch {} \\\; export GOOS=$(goos "$OS") export GOARCH="$ARCH" sh_c mkdir -p "$HW_BUILD_DIR/bin" -sh_c go build -ldflags "-X oss.terrastruct.com/d2/lib/version.Version=$VERSION" \ +sh_c go build -ldflags "'-X oss.terrastruct.com/d2/lib/version.Version=$VERSION'" \ -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR" diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 6f4f2d794..08611160e 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -1,5 +1,9 @@ #!/bin/sh set -eu -$LOG_SH -$RAND_SH +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib/log.sh +. ./ci/sub/lib/flag.sh +cd - + +doing installation here diff --git a/ci/release/build.sh b/ci/release/build.sh index 34570ed52..b9a05d92d 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -37,24 +37,21 @@ main() { return 0 ;; rebuild) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" REBUILD=1 - shift "$FLAGSHIFT" ;; local) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" LOCAL=1 - shift "$FLAGSHIFT" ;; dryrun) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" DRYRUN=1 - shift "$FLAGSHIFT" ;; run) - flag_reqarg - JOB_FILTER="$FLAGARG" - shift "$FLAGSHIFT" + flag_reqarg && shift "$FLAGSHIFT" + JOBFILTER="$FLAGARG" + ;; '') shift "$FLAGSHIFT" break @@ -133,6 +130,7 @@ VERSION=$VERSION \ OS=$OS \ ARCH=$ARCH \ ARCHIVE=$ARCHIVE \ +TERM=$TERM \ ./src/d2/ci/release/build_docker.sh" sh_c rsync --archive --human-readable "$RHOST:src/d2/$ARCHIVE" "$ARCHIVE" } diff --git a/ci/release/build_docker.sh b/ci/release/build_docker.sh index 88aacac87..e9d331800 100755 --- a/ci/release/build_docker.sh +++ b/ci/release/build_docker.sh @@ -5,17 +5,13 @@ cd -- "$(dirname "$0")/../.." tag="$(sh_c docker build \ --build-arg GOVERSION="1.19.3.linux-$ARCH" \ - -qf ./ci/release/builders/Dockerfile ./ci/release/builders )" -sh_c docker run -it --rm \ - -v "$HOME:$HOME" \ - -u "$(id -u):$(id -g)" \ - -w "$HOME" \ - -e DRYRUN="${DRYRUN-}" \ - -e HW_BUILD_DIR="$HW_BUILD_DIR" \ - -e VERSION="$VERSION" \ - -e OS="$OS" \ - -e ARCH="$ARCH" \ - -e ARCHIVE="$ARCHIVE" \ - -e TERM="$TERM" \ - -e HOME="$HOME" \ + -qf ./ci/release/builders/Dockerfile ./ci/release/builders)" +docker_run \ + -e DRYRUN \ + -e HW_BUILD_DIR \ + -e VERSION \ + -e OS \ + -e ARCH \ + -e ARCHIVE \ + -e TERM \ "$tag" ./src/d2/ci/release/_build.sh diff --git a/ci/release/builders/ensure_aws.sh b/ci/release/builders/ensure_aws.sh index 5f2aede0e..b7d0a682f 100755 --- a/ci/release/builders/ensure_aws.sh +++ b/ci/release/builders/ensure_aws.sh @@ -21,9 +21,8 @@ main() { return 0 ;; dryrun) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" DRYRUN=1 - shift "$FLAGSHIFT" ;; '') shift "$FLAGSHIFT" diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index 314b468d1..fd49041d4 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -21,6 +21,7 @@ set -eu # # Generated by ./ci/release/gen_install.sh. # ************* + EOF # sed removes the sourcing dependency lines as we're bundled everything into a single @@ -29,5 +30,6 @@ sh_c cat \ ./ci/sub/lib/rand.sh \ ./ci/sub/lib/log.sh \ ./ci/sub/lib/flag.sh \ - ./ci/release/_install.sh \ - | sed '/^\. /d' >> ./install.sh + \| sed "-e'/^\. /d'" \>\> ./install.sh +sh_c cat ./ci/release/_install.sh \ + \| sed -n "'/cd -- \"\$(dirname/,/cd -/!p'" \>\> install.sh diff --git a/ci/release/release.sh b/ci/release/release.sh index a87b7f37e..6f0aa5395 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -71,19 +71,16 @@ main() { return 0 ;; rebuild) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" REBUILD=1 - shift "$FLAGSHIFT" ;; prerelease) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" PRERELEASE=1 - shift "$FLAGSHIFT" ;; dryrun) - flag_noarg + flag_noarg && shift "$FLAGSHIFT" DRYRUN=1 - shift "$FLAGSHIFT" ;; '') shift "$FLAGSHIFT" diff --git a/ci/sub b/ci/sub index 5d23dec92..d064c179a 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 5d23dec92cee36692bc8c8cece74890cce9631e4 +Subproject commit d064c179a5c102c4f54cf63be058461b21b8e28a diff --git a/install.sh b/install.sh new file mode 100644 index 000000000..e8f5cf3c4 --- /dev/null +++ b/install.sh @@ -0,0 +1,350 @@ +#!/bin/sh +set -eu + +# ************* +# DO NOT EDIT +# +# install.sh was bundled together from +# +# - ./ci/sub/lib/rand.sh +# - ./ci/sub/lib/log.sh +# - ./ci/sub/lib/flag.sh +# - ./ci/release/_install.sh +# +# The last of which implements the installation logic. +# +# Generated by ./ci/release/gen_install.sh. +# ************* + +#!/bin/sh +if [ "${LIB_RAND-}" ]; then + return 0 +fi +LIB_RAND=1 + +rand() { + seed="$1" + range="$2" + + seed_file="$(mktemp)" + _echo "$seed" | md5sum > "$seed_file" + shuf -i "$range" -n 1 --random-source="$seed_file" +} + +pick() { + seed="$1" + shift + i="$(rand "$seed" "1-$#")" + eval "_echo \"\$$i\"" +} +#!/bin/sh +if [ "${LIB_LOG-}" ]; then + return 0 +fi +LIB_LOG=1 + +tput() { + if [ -n "$TERM" ]; then + command tput "$@" + fi +} + +setaf() { + tput setaf "$1" + shift + printf '%s' "$*" + tput sgr0 +} + +_echo() { + printf '%s\n' "$*" +} + +get_rand_color() { + # 1-6 are regular and 9-14 are bright. + # 1,2 and 9,10 are red and green but we use those for success and failure. + pick "$*" 3 4 5 6 11 12 13 14 +} + +echop() { + prefix="$1" + shift + + if [ "$#" -gt 0 ]; then + printfp "$prefix" "%s\n" "$*" + else + printfp "$prefix" + printf '\n' + fi +} + +printfp() {( + prefix="$1" + shift + + if [ -z "${COLOR:-}" ]; then + COLOR="$(get_rand_color "$prefix")" + fi + printf '%s' "$(setaf "$COLOR" "$prefix")" + + if [ $# -gt 0 ]; then + printf ': ' + printf "$@" + fi +)} + +catp() { + prefix="$1" + shift + + printfp "$prefix" + printf ': ' + read -r line + _echo "$line" + + indent=$(repeat ' ' 2) + sed "s/^/$indent/" +} + +repeat() { + char="$1" + times="$2" + seq -s "$char" "$times" | tr -d '[:digit:]' +} + +strlen() { + printf %s "$1" | wc -c +} + +echoerr() { + COLOR=1 echop err "$*" >&2 +} + +caterr() { + COLOR=1 catp err "$@" >&2 +} + +printferr() { + COLOR=1 printfp err "$@" >&2 +} + +logp() { + echop "$@" >&2 +} + +logfp() { + printfp "$@" >&2 +} + +logpcat() { + catp "$@" >&2 +} + +log() { + COLOR=5 logp log "$@" +} + +logf() { + COLOR=5 logfp log "$@" +} + +logcat() { + COLOR=5 catp log "$@" >&2 +} + +sh_c() { + COLOR=3 logp exec "$*" + if [ -z "${DRYRUN-}" ]; then + eval "$@" + fi +} + +header() { + logp "/* $1 */" +} + +hide() { + out="$(mktemp)" + set +e + "$@" >"$out" 2>&1 + code="$?" + set -e + if [ "$code" -eq 0 ]; then + return + fi + cat "$out" >&2 + exit "$code" +} + +echo_dur() { + local dur=$1 + local h=$((dur/60/60)) + local m=$((dur/60%60)) + local s=$((dur%60)) + printf '%dh%dm%ds' "$h" "$m" "$s" +} + +sponge() { + dst="$1" + tmp="$(mktemp)" + cat > "$tmp" + cat "$tmp" > "$dst" +} + +stripansi() { + # First regex gets rid of standard xterm escape sequences for controlling + # visual attributes. + # The second regex I'm not 100% sure, the reference says it selects the US + # encoding but I'm not sure why that's necessary or why it always occurs + # in tput sgr0 before the standard escape sequence. + # See tput sgr0 | xxd + sed -e $'s/\x1b\[[0-9;]*m//g' -e $'s/\x1b(.//g' +} + +runtty() { + case "$(uname)" in + Darwin) + script -q /dev/null "$@" + ;; + Linux) + script -eqc "$*" + ;; + *) + echoerr "runtty: unsupported OS $(uname)" + return 1 + esac +} +#!/bin/sh +if [ "${LIB_FLAG-}" ]; then + return 0 +fi +LIB_FLAG=1 + +# flag_parse implements a robust flag parser. +# +# For a full fledge example see ../examples/date.sh +# +# It differs from getopts(1) in that long form options are supported. Currently the only +# deficiency is that short combined options are not supported like -xyzq. That would be +# interpreted as a single -xyzq flag. The other deficiency is lack of support for short +# flag syntax like -carg where the arg is not separated from the flag. This one is +# unfixable I believe unfortunately but for combined short flags I have opened +# https://github.com/terrastruct/ci/issues/6 +# +# flag_parse stores state in $FLAG, $FLAGRAW, $FLAGARG and $FLAGSHIFT. +# FLAG contains the name of the flag without hyphens. +# FLAGRAW contains the name of the flag as passed in with hyphens. +# FLAGARG contains the argument for the flag if there was any. +# If there was none, it will not be set. +# FLAGSHIFT contains the number by which the arguments should be shifted to +# start at the next flag/argument +# +# After each call check $FLAG for the name of the parsed flag. +# If empty, then no more flags are left. +# Still, call shift "$FLAGSHIFT" in case there was a -- +# +# If the argument for the flag is optional, then use ${FLAGARG-} to access +# the argument if one was passed. Use ${FLAGARG+x} = x to check if it was set. +# You only need to explicitly check if the flag was set if you care whether the user +# explicitly passed the empty string as the argument. +# +# Otherwise, call one of the flag_*arg functions: +# +# If a flag requires an argument, call flag_reqarg +# - $FLAGARG is guaranteed to be set after. +# If a flag requires a non empty argument, call flag_nonemptyarg +# - $FLAGARG is guaranteed to be set to a non empty string after. +# If a flag should not be passed an argument, call flag_noarg +# - $FLAGARG is guaranteed to be unset after. +# +# And then shift "$FLAGSHIFT" +flag_parse() { + case "${1-}" in + -*=*) + # Remove everything after first equal sign. + FLAG="${1%%=*}" + FLAGRAW="$FLAG" + # Remove leading hyphens. + FLAG="${FLAG#-}"; FLAG="${FLAG#-}" + # Remove everything before first equal sign. + FLAGARG="${1#*=}" + FLAGSHIFT=1 + ;; + -) + FLAG= + FLAGRAW= + unset FLAGARG + FLAGSHIFT=0 + ;; + --) + FLAG= + FLAGRAW= + unset FLAGARG + FLAGSHIFT=1 + ;; + -*) + # Remove leading hyphens. + FLAG="${1#-}"; FLAG="${FLAG#-}" + FLAGRAW=$1 + unset FLAGARG + FLAGSHIFT=1 + if [ $# -gt 1 ]; then + case "$2" in + -) + FLAGARG="$2" + FLAGSHIFT=2 + ;; + -*) + ;; + *) + FLAGARG="$2" + FLAGSHIFT=2 + ;; + esac + fi + ;; + *) + FLAG= + FLAGRAW= + unset FLAGARG + FLAGSHIFT=0 + ;; + esac + return 0 +} + +flag_reqarg() { + if [ "${FLAGARG+x}" != x ]; then + flag_errusage "flag $FLAGRAW requires an argument" + fi +} + +flag_nonemptyarg() { + flag_reqarg + if [ -z "$FLAGARG" ]; then + flag_errusage "flag $FLAGRAW requires a non-empty argument" + fi +} + +flag_noarg() { + if [ "$FLAGSHIFT" -eq 2 ]; then + unset FLAGARG + FLAGSHIFT=1 + elif [ "${FLAGARG+x}" = x ]; then + # Means an argument was passed via equal sign as in -$FLAG=$FLAGARG + flag_errusage "flag $FLAGRAW does not accept an argument" + fi +} + +flag_errusage() { + caterr < Date: Sun, 13 Nov 2022 22:41:58 -0800 Subject: [PATCH 18/33] install.sh: Script usage --- ci/release/README.md | 2 ++ ci/release/_install.sh | 69 ++++++++++++++++++++++++++++++++++++- ci/release/build.sh | 43 ++++++++++++++++------- ci/sub | 2 +- install.sh | 77 +++++++++++++++++++++++++++++++++++++++++- 5 files changed, 178 insertions(+), 15 deletions(-) mode change 100644 => 100755 install.sh diff --git a/ci/release/README.md b/ci/release/README.md index 8833ecd0e..4530983e4 100644 --- a/ci/release/README.md +++ b/ci/release/README.md @@ -23,6 +23,8 @@ it depends on from ../sub/lib. > variables as we must compile d2 directly on each release target to include dagre. > See https://github.com/terrastruct/d2/issues/31 +Use `--host-only` to build only the release for the host's OS-ARCH pair. + ### build_docker.sh Helper script called by build.sh to build D2 on each linux runner inside Docker. diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 08611160e..dd0f92f05 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -6,4 +6,71 @@ cd -- "$(dirname "$0")/../.." . ./ci/sub/lib/flag.sh cd - -doing installation here +help() { + arg0="$0" + if [ "$0" = sh ]; then + arg0="curl -fsSL https://d2lang.com/install.sh | sh -s --" + fi + + cat </d2-.tar.gz @@ -14,15 +14,24 @@ commit if available. Flags: ---rebuild: By default build.sh will avoid rebuilding finished assets if they - already exist but if you changed something and need to force rebuild, use - this flag. ---local: By default build.sh uses \$TSTRUCT_MACOS_AMD64_BUILDER, - \$TSTRUCT_MACOS_ARM64_BUILDER, \$TSTRUCT_LINUX_AMD64_BUILDER and - \$TSTRUCT_LINUX_ARM64_BUILDER to build the release archives. It's required for - now due to the following issue: https://github.com/terrastruct/d2/issues/31 - With --local, build.sh will cross compile locally. - warning: This is only for testing purposes, do not use in production! +--rebuild + By default build.sh will avoid rebuilding finished assets if they already exist but if you + changed something and need to force rebuild, use this flag. + +--local + By default build.sh uses \$TSTRUCT_MACOS_AMD64_BUILDER, \$TSTRUCT_MACOS_ARM64_BUILDER, + \$TSTRUCT_LINUX_AMD64_BUILDER and \$TSTRUCT_LINUX_ARM64_BUILDER to build the release + archives. It's required for now due to the following issue: + https://github.com/terrastruct/d2/issues/31 With --local, build.sh will cross compile + locally. warning: This is only for testing purposes, do not use in production! + +--host-only + Use to build the release archive for the host OS-ARCH only. All logging is done to stderr + so in a script you can read from stdout to get the path to the release archive. + +--run=regex + Use to run only the OS-ARCH jobs that match the given regex. e.g. --run=linux only runs + the linux jobs. --run=linux-amd64 only runs the linux-amd64 job. EOF } @@ -52,6 +61,10 @@ main() { flag_reqarg && shift "$FLAGSHIFT" JOBFILTER="$FLAGARG" ;; + host-only) + flag_noarg && shift "$FLAGSHIFT" + HOST_ONLY=1 + ;; '') shift "$FLAGSHIFT" break @@ -66,6 +79,12 @@ main() { flag_errusage "no arguments are accepted" fi + if [ -n "${HOST_ONLY-}" ]; then + runjob $(os)-$(arch) "OS=$(os) ARCH=$(arch) build" & + waitjobs + return 0 + fi + runjob linux-amd64 'OS=linux ARCH=amd64 build' & runjob linux-arm64 'OS=linux ARCH=arm64 build' & runjob macos-amd64 'OS=macos ARCH=amd64 build' & @@ -99,13 +118,13 @@ build() { RHOST=$TSTRUCT_LINUX_ARM64_BUILDER build_rhost ;; *) - COLOR=3 logp warn "no builder for OS=$OS, building locally..." + warn "no builder for OS=$OS, building locally..." build_local ;; esac ;; *) - COLOR=3 logp warn "no builder for OS=$OS, building locally..." + warn "no builder for OS=$OS, building locally..." build_local ;; esac diff --git a/ci/sub b/ci/sub index d064c179a..30d7e137c 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit d064c179a5c102c4f54cf63be058461b21b8e28a +Subproject commit 30d7e137c97f2d2e2960a52adadc5019a02bfa30 diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index e8f5cf3c4..958ed355b --- a/install.sh +++ b/install.sh @@ -152,6 +152,14 @@ logcat() { COLOR=5 catp log "$@" >&2 } +warn() { + COLOR=3 logp warn "$@" +} + +warnf() { + COLOR=3 logfp warn "$@" +} + sh_c() { COLOR=3 logp exec "$*" if [ -z "${DRYRUN-}" ]; then @@ -347,4 +355,71 @@ EOF set -eu -doing installation here +help() { + arg0="$0" + if [ "$0" = sh ]; then + arg0="curl -fsSL https://d2lang.com/install.sh | sh -s --" + fi + + cat < Date: Sun, 13 Nov 2022 22:47:32 -0800 Subject: [PATCH 19/33] README: Add install.sh docs --- README.md | 54 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f4f5f7148..b159f4110 100644 --- a/README.md +++ b/README.md @@ -42,27 +42,61 @@ ## Quickstart (CLI) +To install: + +```sh +# With --dryrun the install script will print the commands it will use +# to install without actually installing so you know what it's going to do. +curl -fsSL https://d2lang.com/install.sh | sh -s -- --dryrun +# If things look good, install for real. +curl -fsSL https://d2lang.com/install.sh | sh -s -- +``` + The most convenient way to use D2 is to just run it as a CLI executable to produce SVGs from `.d2` files. ```sh -go install oss.terrastruct.com/d2 - echo 'x -> y -> z' > in.d2 d2 --watch in.d2 out.svg ``` A browser window will open with `out.svg` and live-reload on changes to `in.d2`. -### MacOS +### Installing from source -Homebrew package coming soon. +```sh +go install oss.terrastruct.com/d2 +``` -### Linux/Windows +### Install We have precompiled binaries on the [releases](https://github.com/terrastruct/d2/releases) -page. D2 will be added to OS-respective package managers soon. +page for macOS and Linux. For both amd64 and arm64. We will release package manager +distributions like .rpm, .deb soon. We also want to get D2 on Homebrew for macOS +and release a docker image +For now, if you don't want to install from source, just use our install script: +Pass `--tala` if you want to install our improved but closed source layout engine +tala. See the docs on [layout engine](#layout-engine) below. + +```sh +# With --dryrun the install script will print the commands it will use +# to install without actually installing so you know what it's going to do. +curl -fsSL https://d2lang.com/install.sh | sh -s -- --dryrun +# If things look good, install for real. +curl -fsSL https://d2lang.com/install.sh | sh -s -- +``` + +To uninstall: + +```sh +curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall --dryrun +# If things look good, install for real. +curl -fsSL https://d2lang.com/install.sh | sh -s -- --uninstall +``` + +> warn: Our binary releases aren't fully portable like normal Go binaries due to the C +> dependency on v8go for executing dagre. ## Quickstart (library) @@ -155,6 +189,14 @@ any single type like "radial" or "tree" (as almost all layout engines are). For information and to download & try TALA, see [https://github.com/terrastruct/TALA](https://github.com/terrastruct/TALA). +You can just pass `--tala` to the install script to install tala as well: + +``` +curl -fsSL https://d2lang.com/install.sh | sh -s -- --tala --dryrun +# If things look good, install for real. +curl -fsSL https://d2lang.com/install.sh | sh -s -- --tala +``` + ## Comparison For a comparison against other popular text-to-diagram tools, see From be6f186ee0b5fdf941e2bcbeef7bb08d6a0403c4 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Sun, 13 Nov 2022 22:59:09 -0800 Subject: [PATCH 20/33] ci: --dryrun -> --dry-run --- ci/release/build.sh | 10 +++++----- ci/release/builders/ensure_aws.sh | 7 +++---- ci/release/release.sh | 6 +++--- ci/sub | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ci/release/build.sh b/ci/release/build.sh index 583eab566..78bc6ab58 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -5,7 +5,7 @@ cd -- "$(dirname "$0")/../.." help() { cat </d2-.tar.gz @@ -53,9 +53,9 @@ main() { flag_noarg && shift "$FLAGSHIFT" LOCAL=1 ;; - dryrun) + dry-run) flag_noarg && shift "$FLAGSHIFT" - DRYRUN=1 + DRY_RUN=1 ;; run) flag_reqarg && shift "$FLAGSHIFT" @@ -131,7 +131,7 @@ build() { } build_local() { - export DRYRUN \ + export DRY_RUN \ HW_BUILD_DIR \ VERSION \ OS \ @@ -143,7 +143,7 @@ build_local() { build_rhost() { sh_c ssh "$RHOST" mkdir -p src sh_c rsync --archive --human-readable --delete ./ "$RHOST:src/d2/" - sh_c ssh -tttt "$RHOST" "DRYRUN=${DRYRUN-} \ + sh_c ssh -tttt "$RHOST" "DRY_RUN=${DRY_RUN-} \ HW_BUILD_DIR=$HW_BUILD_DIR \ VERSION=$VERSION \ OS=$OS \ diff --git a/ci/release/builders/ensure_aws.sh b/ci/release/builders/ensure_aws.sh index b7d0a682f..9e4c35a53 100755 --- a/ci/release/builders/ensure_aws.sh +++ b/ci/release/builders/ensure_aws.sh @@ -5,14 +5,13 @@ cd -- "$(dirname "$0")/../../.." help() { cat < Date: Sun, 13 Nov 2022 23:17:46 -0800 Subject: [PATCH 21/33] install.sh: Implement flag parsing --- ci/release/_install.sh | 77 ++++++++++++++++++++++++++++++++++++++++-- ci/sub | 2 +- 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index dd0f92f05..da48d5f52 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -13,7 +13,7 @@ help() { fi cat < Date: Sun, 13 Nov 2022 23:20:30 -0800 Subject: [PATCH 22/33] ci/release: DRYRUN -> DRY_RUN --- ci/release/build_docker.sh | 2 +- ci/release/template/README.md.sh | 4 +- ci/release/template/scripts/lib.sh | 2 +- install.sh | 91 ++++++++++++++++++++++++++++-- 4 files changed, 89 insertions(+), 10 deletions(-) diff --git a/ci/release/build_docker.sh b/ci/release/build_docker.sh index e9d331800..7c3751af2 100755 --- a/ci/release/build_docker.sh +++ b/ci/release/build_docker.sh @@ -7,7 +7,7 @@ tag="$(sh_c docker build \ --build-arg GOVERSION="1.19.3.linux-$ARCH" \ -qf ./ci/release/builders/Dockerfile ./ci/release/builders)" docker_run \ - -e DRYRUN \ + -e DRY_RUN \ -e HW_BUILD_DIR \ -e VERSION \ -e OS \ diff --git a/ci/release/template/README.md.sh b/ci/release/template/README.md.sh index 84a0c01c2..880483016 100755 --- a/ci/release/template/README.md.sh +++ b/ci/release/template/README.md.sh @@ -11,7 +11,7 @@ version: $VERSION ## Install \`\`\`sh -make install PREFIX=/usr/local DRYRUN=1 +make install PREFIX=/usr/local DRY_RUN=1 # If it looks right, run: make install PREFIX=/usr/local \`\`\` @@ -19,7 +19,7 @@ make install PREFIX=/usr/local ## Uninstall \`\`\`sh -make uninstall PREFIX=/usr/local DRYRUN=1 +make uninstall PREFIX=/usr/local DRY_RUN=1 # If it looks right, run: make uninstall PREFIX=/usr/local \`\`\` diff --git a/ci/release/template/scripts/lib.sh b/ci/release/template/scripts/lib.sh index 074eb3a91..95244284d 100644 --- a/ci/release/template/scripts/lib.sh +++ b/ci/release/template/scripts/lib.sh @@ -127,7 +127,7 @@ logcat() { sh_c() { COLOR=3 logp exec "$*" - if [ -z "${DRYRUN-}" ]; then + if [ -z "${DRY_RUN-}" ]; then "$@" fi } diff --git a/install.sh b/install.sh index 958ed355b..8c8a11f2a 100755 --- a/install.sh +++ b/install.sh @@ -162,7 +162,7 @@ warnf() { sh_c() { COLOR=3 logp exec "$*" - if [ -z "${DRYRUN-}" ]; then + if [ -z "${DRY_RUN-}" ]; then eval "$@" fi } @@ -271,9 +271,9 @@ flag_parse() { -*=*) # Remove everything after first equal sign. FLAG="${1%%=*}" - FLAGRAW="$FLAG" # Remove leading hyphens. FLAG="${FLAG#-}"; FLAG="${FLAG#-}" + FLAGRAW="$(flag_fmt)" # Remove everything before first equal sign. FLAGARG="${1#*=}" FLAGSHIFT=1 @@ -293,7 +293,7 @@ flag_parse() { -*) # Remove leading hyphens. FLAG="${1#-}"; FLAG="${FLAG#-}" - FLAGRAW=$1 + FLAGRAW=$(flag_fmt) unset FLAGARG FLAGSHIFT=1 if [ $# -gt 1 ]; then @@ -351,6 +351,14 @@ Run with --help for usage. EOF return 1 } + +flag_fmt() { + if [ "$(printf %s "$FLAG" | wc -c)" -eq 1 ]; then + echo "-$FLAG" + else + echo "--$FLAG" + fi +} #!/bin/sh set -eu @@ -362,7 +370,7 @@ help() { fi cat < Date: Mon, 14 Nov 2022 02:13:37 -0800 Subject: [PATCH 23/33] install.sh: Get installs working --- ci/release/README.md | 4 + ci/release/_build.sh | 5 +- ci/release/_install.sh | 154 +++++++++++++++++++++++++++++++---- ci/release/build.sh | 18 ++-- ci/release/gen_install.sh | 1 + ci/release/release.sh | 14 +++- ci/release/template/Makefile | 4 +- ci/release/upload_assets.sh | 47 +++++++++++ ci/sub | 2 +- install.sh | 7 ++ lib/version/version.go | 8 +- 11 files changed, 235 insertions(+), 29 deletions(-) create mode 100755 ci/release/upload_assets.sh diff --git a/ci/release/README.md b/ci/release/README.md index 4530983e4..10c4c44b2 100644 --- a/ci/release/README.md +++ b/ci/release/README.md @@ -14,6 +14,10 @@ it depends on from ../sub/lib. - ./release.sh is the top level script to generate a new release. Run with --help for usage. +### upload_assets.sh + +- Called by ./release.sh to upload the assets for the release in $VERSION + ## build.sh - ./build.sh builds the release archives for each platform into ./build//*.tar.gz diff --git a/ci/release/_build.sh b/ci/release/_build.sh index db1b27de9..c5170219a 100755 --- a/ci/release/_build.sh +++ b/ci/release/_build.sh @@ -16,4 +16,7 @@ sh_c mkdir -p "$HW_BUILD_DIR/bin" sh_c go build -ldflags "'-X oss.terrastruct.com/d2/lib/version.Version=$VERSION'" \ -o "$HW_BUILD_DIR/bin/d2" ./cmd/d2 -sh_c tar czf "$ARCHIVE" "$HW_BUILD_DIR" +ARCHIVE=$PWD/$ARCHIVE +cd "$(dirname "$HW_BUILD_DIR")" +sh_c tar -czf "$ARCHIVE" "$(basename "$HW_BUILD_DIR")" +cd ->/dev/null diff --git a/ci/release/_install.sh b/ci/release/_install.sh index da48d5f52..19a909f1c 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -1,10 +1,11 @@ #!/bin/sh set -eu -cd -- "$(dirname "$0")/../.." -. ./ci/sub/lib/log.sh -. ./ci/sub/lib/flag.sh -cd - +cd -- "$(dirname "$0")/../sub/lib" +. ./log.sh +. ./flag.sh +. ./release.sh +cd - >/dev/null help() { arg0="$0" @@ -13,7 +14,7 @@ help() { fi cat </dev/null; then + INSTALLED_VERSION="$(d2 version)" + if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then + log "skipping installation as version $VERSION is already installed." + return 0 + fi + log "uninstalling $INSTALLED_VERSION to install $VERSION" + # uninstall + fi + + install_standalone +} + +install_standalone() { + ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz" + log "installing standalone release $ARCHIVE from github" + + VERSION=$(fetch_version_info) + asset_line=$(cat "$CACHE_DIR/$VERSION.json" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) + asset_url=$(sed -n $((asset_line-3))p "$CACHE_DIR/$VERSION.json" | sed 's/^.*: "\(.*\)",$/\1/g') + fetch_gh "$asset_url" "$CACHE_DIR/$ARCHIVE" 'application/octet-stream' + + sh_c tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/$ARCHIVE" + sh_c cd "$CACHE_DIR/d2-$VERSION" + + sh_c="sh_c" + if !is_prefix_writable; then + sh_c="sudo_sh_c" + fi + "$sh_c" make install PREFIX="$PREFIX" +} + +uninstall() { + log "uninstalling standalone release d2-$VERSION" + + sh_c cd "$CACHE_DIR/d2-$VERSION" + + sh_c="sh_c" + if !is_prefix_writable; then + sh_c="sudo_sh_c" + fi + "$sh_c" make uninstall PREFIX="$PREFIX" +} + +is_prefix_writable() { + sh_c mkdir -p "$PREFIX" 2>/dev/null || true + # The reason for checking whether bin is writable specifically is that on macOS you have + # /usr/local owned by root but you don't need root to write to its subdirectories which + # is all we want to do. + if [ ! -w "$PREFIX/bin" ]; then + return 0 + fi +} + +cache_dir() { + if [ -n "${XDG_CACHE_HOME-}" ]; then + echo "$XDG_CACHE_HOME/d2/release" + elif [ -n "${HOME-}" ]; then + echo "$HOME/.cache/d2/release" + else + echo "/tmp/d2-cache/release" + fi +} + +fetch_version_info() { + req_version=$VERSION + log "fetching info on version $req_version" + if [ -e "$CACHE_DIR/$req_version.json" ]; then + log "reusing $CACHE_DIR/$req_version.json" + fi + + rm -f "$CACHE_DIR/req_version.json" + if [ "$req_version" = latest ]; then + release_info_url="https://api.github.com/repos/$REPO/releases/$req_version" + else + release_info_url="https://api.github.com/repos/$REPO/releases/tags/$req_version" + fi + fetch_gh "$release_info_url" "$CACHE_DIR/$req_version.json" \ + 'application/json' + VERSION=$(cat "$CACHE_DIR/$req_version.json" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') + if [ "$req_version" = latest ]; then + mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" + fi + echo "$VERSION" +} + +curl_gh() { + sh_c curl -fL ${GITHUB_TOKEN+"-H \"Authorization: Bearer \$GITHUB_TOKEN\""} "$@" +} + +fetch_gh() { + url=$1 + file=$2 + accept=$3 + + if [ -e "$file" ]; then + log "reusing $file" + return + fi + + curl_gh -#o "$file.inprogress" -C- -H "'Accept: $accept'" "$url" + sh_c mv "$file.inprogress" "$file" } main "$@" diff --git a/ci/release/build.sh b/ci/release/build.sh index 78bc6ab58..8aaec7c93 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -7,7 +7,7 @@ help() { cat </d2-.tar.gz +$0 builds D2 release archives into ./ci/release/build//d2---.tar.gz The version is detected via git describe which will use the git tag for the current commit if available. @@ -32,12 +32,13 @@ Flags: --run=regex Use to run only the OS-ARCH jobs that match the given regex. e.g. --run=linux only runs the linux jobs. --run=linux-amd64 only runs the linux-amd64 job. + +--version vX.X.X + Use to overwrite the version detected from git. EOF } main() { - VERSION="$(git_describe_ref)" - BUILD_DIR="ci/release/build/$VERSION" while :; do flag_parse "$@" case "$FLAG" in @@ -64,6 +65,11 @@ main() { host-only) flag_noarg && shift "$FLAGSHIFT" HOST_ONLY=1 + LOCAL=1 + ;; + version) + flag_nonemptyarg && shift "$FLAGSHIFT" + VERSION=$FLAGARG ;; '') shift "$FLAGSHIFT" @@ -79,6 +85,8 @@ main() { flag_errusage "no arguments are accepted" fi + VERSION=${VERSION:-$(git_describe_ref)} + BUILD_DIR=ci/release/build/$VERSION if [ -n "${HOST_ONLY-}" ]; then runjob $(os)-$(arch) "OS=$(os) ARCH=$(arch) build" & waitjobs @@ -93,8 +101,8 @@ main() { } build() { - HW_BUILD_DIR="$BUILD_DIR/$OS/$ARCH/d2-$VERSION" - ARCHIVE="$BUILD_DIR/d2-$OS-$ARCH-$VERSION.tar.gz" + HW_BUILD_DIR="$BUILD_DIR/$OS-$ARCH/d2-$VERSION" + ARCHIVE="$BUILD_DIR/d2-$VERSION-$OS-$ARCH.tar.gz" if [ -e "$ARCHIVE" -a -z "${REBUILD-}" ]; then log "skipping as already built at $ARCHIVE" diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index fd49041d4..def56ac2f 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -30,6 +30,7 @@ sh_c cat \ ./ci/sub/lib/rand.sh \ ./ci/sub/lib/log.sh \ ./ci/sub/lib/flag.sh \ + ./ci/sub/lib/release.sh \ \| sed "-e'/^\. /d'" \>\> ./install.sh sh_c cat ./ci/release/_install.sh \ \| sed -n "'/cd -- \"\$(dirname/,/cd -/!p'" \>\> install.sh diff --git a/ci/release/release.sh b/ci/release/release.sh index 56bb2c023..45850cd50 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -21,6 +21,8 @@ Flags: changelogs/v0.0.99-alpha.1.md. This is because you want to maintain the changelog entries for the eventual final release. --dry-run: Print the commands that would be ran without executing them. +--skip-build: Skip the build in case you want to upload your own specific assets. + Mainly for testing and debugging. Process: @@ -82,6 +84,10 @@ main() { flag_noarg && shift "$FLAGSHIFT" DRY_RUN=1 ;; + skip-build) + flag_noarg && shift "$FLAGSHIFT" + SKIP_BUILD=1 + ;; '') shift "$FLAGSHIFT" break @@ -185,15 +191,19 @@ _7_ensure_pr() { return 0 fi - pr_url="$(sh_c gh pr create --fill --body "$body" | tee /dev/stderr)" + pr_url="$(sh_c gh pr create --fill --body "'$body'" | tee /dev/stderr)" } _8_ensure_assets() { + if [ "${SKIP_BUILD-}" ]; then + warn "skipping building of assets due to --skip-build" + return 0 + fi sh_c ./ci/release/build.sh ${REBUILD:+--rebuild} } _9_upload_assets() { - sh_c gh release upload --clobber "$VERSION" "./ci/release/build/$VERSION"/*.tar.gz + ./ci/release/upload_assets.sh $VERSION } main "$@" diff --git a/ci/release/template/Makefile b/ci/release/template/Makefile index a93267ed7..5b9ba1353 100644 --- a/ci/release/template/Makefile +++ b/ci/release/template/Makefile @@ -5,8 +5,8 @@ PREFIX = $(DESTDIR)/usr/local .PHONY: install install: - ./scripts/install.sh + PREFIX='$(PREFIX)' ./scripts/install.sh .PHONY: uninstall uninstall: - ./scripts/uninstall.sh + PREFIX='$(PREFIX)' ./scripts/uninstall.sh diff --git a/ci/release/upload_assets.sh b/ci/release/upload_assets.sh new file mode 100755 index 000000000..f14da46b6 --- /dev/null +++ b/ci/release/upload_assets.sh @@ -0,0 +1,47 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../.." +. ./ci/sub/lib.sh + +help() { + cat < + +Uploads the assets for release to GitHub. + +For example, if is v0.0.99 then it uploads files matching +./ci/release/build/v0.0.99/*.tar.gz to the GitHub release v0.0.99. + +Example: + $0 v0.0.99 +EOF +} + +main() { + while :; do + flag_parse "$@" + case "$FLAG" in + h|help) + help + return 0 + ;; + '') + shift "$FLAGSHIFT" + break + ;; + *) + flag_errusage "unrecognized flag $FLAGRAW" + ;; + esac + done + + if [ $# -ne 1 ]; then + flag_errusage "first argument must be release version like v0.0.99" + fi + VERSION="$1" + shift + + sh_c gh release upload --clobber "$VERSION" "./ci/release/build/$VERSION"/*.tar.gz +} + +main "$@" diff --git a/ci/sub b/ci/sub index 81e033b77..5a1c8e5e3 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 81e033b7702131e917a16396b44c20512d29029b +Subproject commit 5a1c8e5e36a0b0c4b0d5e2ad4e08c3c815dd4bea diff --git a/install.sh b/install.sh index 8c8a11f2a..061999567 100755 --- a/install.sh +++ b/install.sh @@ -499,6 +499,13 @@ main() { if [ $# -gt 0 ]; then flag_errusage "no arguments are accepted" fi + + REPO=${REPO:-terrastruct/d2} + latest_version +} + +latest_version() { + curl -fsSLI -o/dev/null -w '%{url_effective}' "https://github.com/$REPO/latest" } main "$@" diff --git a/lib/version/version.go b/lib/version/version.go index ef7703a06..65db5ca1c 100644 --- a/lib/version/version.go +++ b/lib/version/version.go @@ -2,6 +2,7 @@ package version import ( "context" + "fmt" "github.com/google/go-github/github" "oss.terrastruct.com/cmdlog" @@ -11,12 +12,17 @@ import ( var Version = "master (built from source)" func CheckVersion(ctx context.Context, logger *cmdlog.Logger) { - logger.Info.Printf("D2 version: %s\n", Version) + fmt.Println(Version) if Version == "master (built from source)" { return } + // Install script uses -v to check the version, we shouldn't be checking for + // updates here... + // https://github.com/terrastruct/d2/issues/49#issuecomment-1313229683 + return + logger.Info.Printf("Checking for updates...") latest, err := getLatestVersion(ctx) if err != nil { From acad492cecf17d6fd01c6cb1d002db189fc48001 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 02:48:47 -0800 Subject: [PATCH 24/33] install.sh: Many many improvements Closes #81 --- ci/release/_install.sh | 88 +++++++++---- install.sh | 277 +++++++++++++++++++++++++++++++++++------ 2 files changed, 303 insertions(+), 62 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 19a909f1c..b4d1c85f3 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -63,18 +63,21 @@ Flags: Install the passed version of tala instead of latest. --force: - Force installation over the existing version even if they match. It will attempt a clean - uninstall first before installing the new version. The install assets will not be deleted - from ~/.cache/d2/install. + Force installation over the existing version even if they match. It will attempt a + uninstall first before installing the new version. The release assets will be deleted + from ~/.cache/d2/release and ~/.local/share/d2/release --uninstall: - Uninstall the installed version of d2. The --method flag must be the same as for - installation. i.e if you used --method standalone you must again use --method standalone - for uninstallation. With detect, the install script will try to use the OS package manager - to uninstall instead. + Uninstall the installed version of d2. The --method and --prefix flags must be the same + as for installation. i.e if you used --method standalone you must again use --method + standalone for uninstallation. With detect, the install script will try to use the OS + package manager to uninstall instead. -All downloaded assets are cached into ~/.cache/d2/release. use \$XDG_CACHE_HOME to change -path of the cached assets. +All downloaded archives are cached into ~/.cache/d2/release. use \$XDG_CACHE_HOME to change +path of the cached assets. Archives will be unarchived into ~/.local/share/d2/release. +Use \$XDG_DATA_HOME to adjust the path of the unarchived releases. + +note: Deleting the unarchived releases will cause --uninstall to stop working. You can rerun install.sh to update your version of D2. install.sh will avoid reinstalling if the installed version is the latest unless --force is passed. @@ -144,22 +147,35 @@ main() { flag_errusage "no arguments are accepted" fi - if [ -n "${UNINSTALL-}" ]; then - uninstall - return 1 - fi - REPO=${REPO:-terrastruct/d2} PREFIX=${PREFIX:-/usr/local} OS=$(os) ARCH=$(arch) CACHE_DIR=$(cache_dir) mkdir -p "$CACHE_DIR" + DATA_DIR=$(data_dir) + mkdir -p "$DATA_DIR" + + if [ -n "${UNINSTALL-}" ]; then + if ! command -v d2 >/dev/null; then + echoerr "no version of d2 installed" + return 1 + fi + INSTALLED_VERSION="$(d2 version)" + if ! uninstall_standalone; then + echoerr "failed to uninstall $INSTALLED_VERSION" + return 1 + fi + return 0 + fi + VERSION=${VERSION:-latest} if [ "$VERSION" = latest ]; then VERSION=$(fetch_version_info) fi + # TODO: --tala, --tala-version + if command -v d2 >/dev/null; then INSTALLED_VERSION="$(d2 version)" if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then @@ -167,7 +183,9 @@ main() { return 0 fi log "uninstalling $INSTALLED_VERSION to install $VERSION" - # uninstall + if ! uninstall_standalone; then + warn "failed to uninstall $INSTALLED_VERSION" + fi fi install_standalone @@ -182,26 +200,35 @@ install_standalone() { asset_url=$(sed -n $((asset_line-3))p "$CACHE_DIR/$VERSION.json" | sed 's/^.*: "\(.*\)",$/\1/g') fetch_gh "$asset_url" "$CACHE_DIR/$ARCHIVE" 'application/octet-stream' - sh_c tar -C "$CACHE_DIR" -xzf "$CACHE_DIR/$ARCHIVE" - sh_c cd "$CACHE_DIR/d2-$VERSION" + sh_c tar -C "$DATA_DIR" -xzf "$CACHE_DIR/$ARCHIVE" + sh_c cd "$DATA_DIR/d2-$VERSION" sh_c="sh_c" - if !is_prefix_writable; then + if ! is_prefix_writable; then sh_c="sudo_sh_c" fi "$sh_c" make install PREFIX="$PREFIX" } -uninstall() { - log "uninstalling standalone release d2-$VERSION" +uninstall_standalone() { + log "uninstalling standalone release d2-$INSTALLED_VERSION" - sh_c cd "$CACHE_DIR/d2-$VERSION" + if [ ! -e "$DATA_DIR/d2-$INSTALLED_VERSION" ]; then + echoerr "no standalone release directory for d2-$INSTALLED_VERSION" + return 1 + fi + + sh_c cd "$DATA_DIR/d2-$INSTALLED_VERSION" sh_c="sh_c" - if !is_prefix_writable; then + if ! is_prefix_writable; then sh_c="sudo_sh_c" fi "$sh_c" make uninstall PREFIX="$PREFIX" + + sh_c rm -rf "$DATA_DIR/d2-$INSTALLED_VERSION" + sh_c rm -rf "$CACHE_DIR/$INSTALLED_VERSION.json" + sh_c rm -rf "$CACHE_DIR/d2-$INSTALLED_VERSION-$OS-$ARCH.tar.gz" } is_prefix_writable() { @@ -224,12 +251,23 @@ cache_dir() { fi } +data_dir() { + if [ -n "${XDG_DATA_HOME-}" ]; then + echo "$XDG_DATA_HOME/d2/release" + elif [ -n "${HOME-}" ]; then + echo "$HOME/.local/d2/release" + else + echo "/tmp/d2-data/release" + fi +} + fetch_version_info() { req_version=$VERSION - log "fetching info on version $req_version" if [ -e "$CACHE_DIR/$req_version.json" ]; then - log "reusing $CACHE_DIR/$req_version.json" + echo "$VERSION" + return 0 fi + log "fetching info on version $req_version" rm -f "$CACHE_DIR/req_version.json" if [ "$req_version" = latest ]; then @@ -241,7 +279,7 @@ fetch_version_info() { 'application/json' VERSION=$(cat "$CACHE_DIR/$req_version.json" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') if [ "$req_version" = latest ]; then - mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" + sh_c mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" fi echo "$VERSION" } diff --git a/install.sh b/install.sh index 061999567..473731ecc 100755 --- a/install.sh +++ b/install.sh @@ -97,13 +97,7 @@ catp() { prefix="$1" shift - printfp "$prefix" - printf ': ' - read -r line - _echo "$line" - - indent=$(repeat ' ' 2) - sed "s/^/$indent/" + sed "s/^/$(printfp "$prefix" '')/" } repeat() { @@ -117,27 +111,27 @@ strlen() { } echoerr() { - COLOR=1 echop err "$*" >&2 + COLOR=1 echop err "$*" | humanpath>&2 } caterr() { - COLOR=1 catp err "$@" >&2 + COLOR=1 catp err "$@" | humanpath >&2 } printferr() { - COLOR=1 printfp err "$@" >&2 + COLOR=1 printfp err "$@" | humanpath >&2 } logp() { - echop "$@" >&2 + echop "$@" | humanpath >&2 } logfp() { - printfp "$@" >&2 + printfp "$@" | humanpath >&2 } logpcat() { - catp "$@" >&2 + catp "$@" | humanpath >&2 } log() { @@ -167,10 +161,38 @@ sh_c() { fi } +sudo_sh_c() { + if [ "$(id -u)" -eq 0 ]; then + sh_c "$@" + elif command -v doas >/dev/null; then + sh_c "doas $*" + elif command -v sudo >/dev/null; then + sh_c "sudo $*" + elif command -v su >/dev/null; then + sh_c "su root -c '$*'" + else + caterr </dev/null; then + echoerr "no version of d2 installed" + return 1 + fi + INSTALLED_VERSION="$(d2 version)" + if ! uninstall_standalone; then + echoerr "failed to uninstall $INSTALLED_VERSION" + return 1 + fi + return 0 + fi + + VERSION=${VERSION:-latest} + if [ "$VERSION" = latest ]; then + VERSION=$(fetch_version_info) + fi + + # TODO: --tala, --tala-version + + if command -v d2 >/dev/null; then + INSTALLED_VERSION="$(d2 version)" + if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then + log "skipping installation as version $VERSION is already installed." + return 0 + fi + log "uninstalling $INSTALLED_VERSION to install $VERSION" + if ! uninstall_standalone; then + warn "failed to uninstall $INSTALLED_VERSION" + fi + fi + + install_standalone } -latest_version() { - curl -fsSLI -o/dev/null -w '%{url_effective}' "https://github.com/$REPO/latest" +install_standalone() { + ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz" + log "installing standalone release $ARCHIVE from github" + + VERSION=$(fetch_version_info) + asset_line=$(cat "$CACHE_DIR/$VERSION.json" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) + asset_url=$(sed -n $((asset_line-3))p "$CACHE_DIR/$VERSION.json" | sed 's/^.*: "\(.*\)",$/\1/g') + fetch_gh "$asset_url" "$CACHE_DIR/$ARCHIVE" 'application/octet-stream' + + sh_c tar -C "$DATA_DIR" -xzf "$CACHE_DIR/$ARCHIVE" + sh_c cd "$DATA_DIR/d2-$VERSION" + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + "$sh_c" make install PREFIX="$PREFIX" +} + +uninstall_standalone() { + log "uninstalling standalone release d2-$INSTALLED_VERSION" + + if [ ! -e "$DATA_DIR/d2-$INSTALLED_VERSION" ]; then + echoerr "no standalone release directory for d2-$INSTALLED_VERSION" + return 1 + fi + + sh_c cd "$DATA_DIR/d2-$INSTALLED_VERSION" + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + "$sh_c" make uninstall PREFIX="$PREFIX" + + sh_c rm -rf "$DATA_DIR/d2-$INSTALLED_VERSION" + sh_c rm -rf "$CACHE_DIR/$INSTALLED_VERSION.json" + sh_c rm -rf "$CACHE_DIR/d2-$INSTALLED_VERSION-$OS-$ARCH.tar.gz" +} + +is_prefix_writable() { + sh_c mkdir -p "$PREFIX" 2>/dev/null || true + # The reason for checking whether bin is writable specifically is that on macOS you have + # /usr/local owned by root but you don't need root to write to its subdirectories which + # is all we want to do. + if [ ! -w "$PREFIX/bin" ]; then + return 0 + fi +} + +cache_dir() { + if [ -n "${XDG_CACHE_HOME-}" ]; then + echo "$XDG_CACHE_HOME/d2/release" + elif [ -n "${HOME-}" ]; then + echo "$HOME/.cache/d2/release" + else + echo "/tmp/d2-cache/release" + fi +} + +data_dir() { + if [ -n "${XDG_DATA_HOME-}" ]; then + echo "$XDG_DATA_HOME/d2/release" + elif [ -n "${HOME-}" ]; then + echo "$HOME/.local/d2/release" + else + echo "/tmp/d2-data/release" + fi +} + +fetch_version_info() { + req_version=$VERSION + if [ -e "$CACHE_DIR/$req_version.json" ]; then + echo "$VERSION" + return 0 + fi + log "fetching info on version $req_version" + + rm -f "$CACHE_DIR/req_version.json" + if [ "$req_version" = latest ]; then + release_info_url="https://api.github.com/repos/$REPO/releases/$req_version" + else + release_info_url="https://api.github.com/repos/$REPO/releases/tags/$req_version" + fi + fetch_gh "$release_info_url" "$CACHE_DIR/$req_version.json" \ + 'application/json' + VERSION=$(cat "$CACHE_DIR/$req_version.json" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') + if [ "$req_version" = latest ]; then + sh_c mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" + fi + echo "$VERSION" +} + +curl_gh() { + sh_c curl -fL ${GITHUB_TOKEN+"-H \"Authorization: Bearer \$GITHUB_TOKEN\""} "$@" +} + +fetch_gh() { + url=$1 + file=$2 + accept=$3 + + if [ -e "$file" ]; then + log "reusing $file" + return + fi + + curl_gh -#o "$file.inprogress" -C- -H "'Accept: $accept'" "$url" + sh_c mv "$file.inprogress" "$file" } main "$@" From da95361ceb14348cd3d04eb2ee7e28f864e465a5 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 03:40:35 -0800 Subject: [PATCH 25/33] install.sh: Many more improvements and fixes --- ci/release/_install.sh | 138 ++++++++++++++++++------------------- ci/release/gen_install.sh | 1 + install.sh | 139 +++++++++++++++++++------------------- 3 files changed, 142 insertions(+), 136 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index b4d1c85f3..66cf1ac03 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -15,7 +15,7 @@ help() { cat < but the release archive in + ~/.cache/d2/release will remain. --uninstall: Uninstall the installed version of d2. The --method and --prefix flags must be the same @@ -74,8 +75,7 @@ Flags: package manager to uninstall instead. All downloaded archives are cached into ~/.cache/d2/release. use \$XDG_CACHE_HOME to change -path of the cached assets. Archives will be unarchived into ~/.local/share/d2/release. -Use \$XDG_DATA_HOME to adjust the path of the unarchived releases. +path of the cached assets. Release archives are unarchived into /usr/local/lib/d2/d2- note: Deleting the unarchived releases will cause --uninstall to stop working. @@ -105,21 +105,21 @@ main() { flag_nonemptyarg && shift "$FLAGSHIFT" VERSION=$FLAGARG ;; - tala-version) - flag_nonemptyarg && shift "$FLAGSHIFT" - TALA_VERSION=$FLAGARG + tala) + shift "$FLAGSHIFT" + TALA=${FLAGARG:-latest} ;; edge) flag_noarg && shift "$FLAGSHIFT" EDGE=1 echoerr "$FLAGRAW is currently unimplemented" - exit 1 + return 1 ;; method) flag_nonemptyarg && shift "$FLAGSHIFT" METHOD=$FLAGARG echoerr "$FLAGRAW is currently unimplemented" - exit 1 + return 1 ;; prefix) flag_nonemptyarg && shift "$FLAGSHIFT" @@ -153,8 +153,7 @@ main() { ARCH=$(arch) CACHE_DIR=$(cache_dir) mkdir -p "$CACHE_DIR" - DATA_DIR=$(data_dir) - mkdir -p "$DATA_DIR" + INSTALL_DIR=$PREFIX/lib/d2 if [ -n "${UNINSTALL-}" ]; then if ! command -v d2 >/dev/null; then @@ -162,7 +161,7 @@ main() { return 1 fi INSTALLED_VERSION="$(d2 version)" - if ! uninstall_standalone; then + if ! uninstall; then echoerr "failed to uninstall $INSTALLED_VERSION" return 1 fi @@ -171,11 +170,9 @@ main() { VERSION=${VERSION:-latest} if [ "$VERSION" = latest ]; then - VERSION=$(fetch_version_info) + fetch_release_info fi - # TODO: --tala, --tala-version - if command -v d2 >/dev/null; then INSTALLED_VERSION="$(d2 version)" if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then @@ -183,56 +180,77 @@ main() { return 0 fi log "uninstalling $INSTALLED_VERSION to install $VERSION" - if ! uninstall_standalone; then + if ! uninstall; then warn "failed to uninstall $INSTALLED_VERSION" fi fi - - install_standalone + install } -install_standalone() { +install() { + standalone_install + if [ "${TALA-}" ]; then + standalone_install_tala + fi + + COLOR=2 header success + log "Standalone release $ARCHIVE has been successfully installed into $PREFIX" + if ! echo "$PATH" | grep -qF "$PREFIX/bin"; then + logcat >&2 </dev/null || true + sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true # The reason for checking whether bin is writable specifically is that on macOS you have # /usr/local owned by root but you don't need root to write to its subdirectories which # is all we want to do. @@ -251,37 +269,21 @@ cache_dir() { fi } -data_dir() { - if [ -n "${XDG_DATA_HOME-}" ]; then - echo "$XDG_DATA_HOME/d2/release" - elif [ -n "${HOME-}" ]; then - echo "$HOME/.local/d2/release" - else - echo "/tmp/d2-data/release" - fi -} - -fetch_version_info() { - req_version=$VERSION - if [ -e "$CACHE_DIR/$req_version.json" ]; then - echo "$VERSION" +fetch_release_info() { + if [ -n "${RELEASE_INFO-}" ]; then return 0 fi - log "fetching info on version $req_version" - rm -f "$CACHE_DIR/req_version.json" - if [ "$req_version" = latest ]; then - release_info_url="https://api.github.com/repos/$REPO/releases/$req_version" + log "fetching info on version $VERSION" + RELEASE_INFO=$(mktemp -d)/release-info.json + if [ "$VERSION" = latest ]; then + release_info_url="https://api.github.com/repos/$REPO/releases/$VERSION" else - release_info_url="https://api.github.com/repos/$REPO/releases/tags/$req_version" + release_info_url="https://api.github.com/repos/$REPO/releases/tags/$VERSION" fi - fetch_gh "$release_info_url" "$CACHE_DIR/$req_version.json" \ + fetch_gh "$release_info_url" "$RELEASE_INFO" \ 'application/json' - VERSION=$(cat "$CACHE_DIR/$req_version.json" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') - if [ "$req_version" = latest ]; then - sh_c mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" - fi - echo "$VERSION" + VERSION=$(cat "$RELEASE_INFO" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') } curl_gh() { diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index def56ac2f..b04325cc2 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -15,6 +15,7 @@ set -eu # - ./ci/sub/lib/rand.sh # - ./ci/sub/lib/log.sh # - ./ci/sub/lib/flag.sh +# - ./ci/sub/lib/release.sh # - ./ci/release/_install.sh # # The last of which implements the installation logic. diff --git a/install.sh b/install.sh index 473731ecc..65b779364 100755 --- a/install.sh +++ b/install.sh @@ -9,6 +9,7 @@ set -eu # - ./ci/sub/lib/rand.sh # - ./ci/sub/lib/log.sh # - ./ci/sub/lib/flag.sh +# - ./ci/sub/lib/release.sh # - ./ci/release/_install.sh # # The last of which implements the installation logic. @@ -424,7 +425,7 @@ help() { cat < but the release archive in + ~/.cache/d2/release will remain. --uninstall: Uninstall the installed version of d2. The --method and --prefix flags must be the same @@ -483,8 +485,7 @@ Flags: package manager to uninstall instead. All downloaded archives are cached into ~/.cache/d2/release. use \$XDG_CACHE_HOME to change -path of the cached assets. Archives will be unarchived into ~/.local/share/d2/release. -Use \$XDG_DATA_HOME to adjust the path of the unarchived releases. +path of the cached assets. Release archives are unarchived into /usr/local/lib/d2/d2- note: Deleting the unarchived releases will cause --uninstall to stop working. @@ -514,21 +515,21 @@ main() { flag_nonemptyarg && shift "$FLAGSHIFT" VERSION=$FLAGARG ;; - tala-version) - flag_nonemptyarg && shift "$FLAGSHIFT" - TALA_VERSION=$FLAGARG + tala) + shift "$FLAGSHIFT" + TALA=${FLAGARG:-latest} ;; edge) flag_noarg && shift "$FLAGSHIFT" EDGE=1 echoerr "$FLAGRAW is currently unimplemented" - exit 1 + return 1 ;; method) flag_nonemptyarg && shift "$FLAGSHIFT" METHOD=$FLAGARG echoerr "$FLAGRAW is currently unimplemented" - exit 1 + return 1 ;; prefix) flag_nonemptyarg && shift "$FLAGSHIFT" @@ -562,8 +563,7 @@ main() { ARCH=$(arch) CACHE_DIR=$(cache_dir) mkdir -p "$CACHE_DIR" - DATA_DIR=$(data_dir) - mkdir -p "$DATA_DIR" + INSTALL_DIR=$PREFIX/lib/d2 if [ -n "${UNINSTALL-}" ]; then if ! command -v d2 >/dev/null; then @@ -571,7 +571,7 @@ main() { return 1 fi INSTALLED_VERSION="$(d2 version)" - if ! uninstall_standalone; then + if ! uninstall; then echoerr "failed to uninstall $INSTALLED_VERSION" return 1 fi @@ -580,11 +580,9 @@ main() { VERSION=${VERSION:-latest} if [ "$VERSION" = latest ]; then - VERSION=$(fetch_version_info) + fetch_release_info fi - # TODO: --tala, --tala-version - if command -v d2 >/dev/null; then INSTALLED_VERSION="$(d2 version)" if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then @@ -592,56 +590,77 @@ main() { return 0 fi log "uninstalling $INSTALLED_VERSION to install $VERSION" - if ! uninstall_standalone; then + if ! uninstall; then warn "failed to uninstall $INSTALLED_VERSION" fi fi - - install_standalone + install } -install_standalone() { +install() { + standalone_install + if [ "${TALA-}" ]; then + standalone_install_tala + fi + + COLOR=2 header success + log "Standalone release $ARCHIVE has been successfully installed into $PREFIX" + if ! echo "$PATH" | grep -qF "$PREFIX/bin"; then + logcat >&2 </dev/null || true + sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true # The reason for checking whether bin is writable specifically is that on macOS you have # /usr/local owned by root but you don't need root to write to its subdirectories which # is all we want to do. @@ -660,37 +679,21 @@ cache_dir() { fi } -data_dir() { - if [ -n "${XDG_DATA_HOME-}" ]; then - echo "$XDG_DATA_HOME/d2/release" - elif [ -n "${HOME-}" ]; then - echo "$HOME/.local/d2/release" - else - echo "/tmp/d2-data/release" - fi -} - -fetch_version_info() { - req_version=$VERSION - if [ -e "$CACHE_DIR/$req_version.json" ]; then - echo "$VERSION" +fetch_release_info() { + if [ -n "${RELEASE_INFO-}" ]; then return 0 fi - log "fetching info on version $req_version" - rm -f "$CACHE_DIR/req_version.json" - if [ "$req_version" = latest ]; then - release_info_url="https://api.github.com/repos/$REPO/releases/$req_version" + log "fetching info on version $VERSION" + RELEASE_INFO=$(mktemp -d)/release-info.json + if [ "$VERSION" = latest ]; then + release_info_url="https://api.github.com/repos/$REPO/releases/$VERSION" else - release_info_url="https://api.github.com/repos/$REPO/releases/tags/$req_version" + release_info_url="https://api.github.com/repos/$REPO/releases/tags/$VERSION" fi - fetch_gh "$release_info_url" "$CACHE_DIR/$req_version.json" \ + fetch_gh "$release_info_url" "$RELEASE_INFO" \ 'application/json' - VERSION=$(cat "$CACHE_DIR/$req_version.json" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') - if [ "$req_version" = latest ]; then - sh_c mv "$CACHE_DIR/$req_version.json" "$CACHE_DIR/$VERSION.json" - fi - echo "$VERSION" + VERSION=$(cat "$RELEASE_INFO" | grep -m1 tag_name | sed 's/^.*: "\(.*\)",$/\1/g') } curl_gh() { From 8099bc564045bbccc82cd61f4a0101a03bbe7e20 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 04:02:23 -0800 Subject: [PATCH 26/33] install.sh: Add --tala support --- ci/release/_install.sh | 124 +++++++++++++++++++++++++++++--------- ci/release/gen_install.sh | 2 +- install.sh | 124 +++++++++++++++++++++++++++++--------- 3 files changed, 191 insertions(+), 59 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 66cf1ac03..170d9d798 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -156,15 +156,7 @@ main() { INSTALL_DIR=$PREFIX/lib/d2 if [ -n "${UNINSTALL-}" ]; then - if ! command -v d2 >/dev/null; then - echoerr "no version of d2 installed" - return 1 - fi - INSTALLED_VERSION="$(d2 version)" - if ! uninstall; then - echoerr "failed to uninstall $INSTALLED_VERSION" - return 1 - fi + uninstall return 0 fi @@ -173,24 +165,13 @@ main() { fetch_release_info fi - if command -v d2 >/dev/null; then - INSTALLED_VERSION="$(d2 version)" - if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then - log "skipping installation as version $VERSION is already installed." - return 0 - fi - log "uninstalling $INSTALLED_VERSION to install $VERSION" - if ! uninstall; then - warn "failed to uninstall $INSTALLED_VERSION" - fi - fi install } install() { - standalone_install + install_d2 if [ "${TALA-}" ]; then - standalone_install_tala + install_tala fi COLOR=2 header success @@ -207,14 +188,23 @@ EOF fi } -uninstall() { - standalone_uninstall - if [ "${TALA-}" ]; then - standalone_uninstall_tala +install_d2() { + if command -v d2 >/dev/null; then + INSTALLED_VERSION="$(d2 version)" + if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then + log "skipping installation as version $VERSION is already installed." + return 0 + fi + log "uninstalling $INSTALLED_VERSION to install $VERSION" + if ! uninstall_d2; then + warn "failed to uninstall $INSTALLED_VERSION" + fi fi + + install_standalone_d2 } -standalone_install() { +install_standalone_d2() { ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz" header "installing standalone release $ARCHIVE from github" @@ -232,11 +222,66 @@ standalone_install() { "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2-$VERSION\" && make install PREFIX=\"$PREFIX\"'" } -standalone_uninstall() { +install_tala() { + install_standalone_tala +} + +install_standalone_tala() { + REPO="${REPO_TALA:-terrastruct/TALA}" + VERSION=${TALA:-latest} + RELEASE_INFO= + fetch_release_info + + ARCHIVE="d2plugin-tala-$VERSION-$OS-$ARCH.tar.gz" + header "installing standalone release $ARCHIVE from github" + + asset_line=$(cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) + asset_url=$(sed -n $((asset_line-3))p "$RELEASE_INFO" | sed 's/^.*: "\(.*\)",$/\1/g') + + fetch_gh "$asset_url" "$CACHE_DIR/$ARCHIVE" 'application/octet-stream' + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + + "$sh_c" tar -C "$INSTALL_DIR" -xzf "$CACHE_DIR/$ARCHIVE" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" +} + +uninstall() { + if ! command -v d2 >/dev/null; then + echoerr "no version of d2 installed" + return 1 + fi + INSTALLED_VERSION="$(d2 --version)" + if ! uninstall_d2; then + echoerr "failed to uninstall $INSTALLED_VERSION" + return 1 + fi + if [ "${TALA-}" ]; then + if ! command -v d2plugin-tala >/dev/null; then + echoerr "no version of d2plugin-tala installed" + return 1 + fi + INSTALLED_VERSION="$(d2plugin-tala --version)" + if ! uninstall_tala; then + echoerr "failed to uninstall d2plugin-tala $INSTALLED_VERSION" + return 1 + fi + fi + return 0 +} + +uninstall_d2() { + uninstall_standalone_d2 +} + +uninstall_standalone_d2() { header "uninstalling standalone release d2-$INSTALLED_VERSION" if [ ! -e "$INSTALL_DIR/d2-$INSTALLED_VERSION" ]; then - echoerr "no installed release directory for d2-$INSTALLED_VERSION in $INSTALL_DIR/d2-$INSTALLED_VERSION" + echoerr "missing standalone install release directory $INSTALL_DIR/d2-$INSTALLED_VERSION" return 1 fi @@ -249,6 +294,27 @@ standalone_uninstall() { "$sh_c" rm -rf "$INSTALL_DIR/d2-$INSTALLED_VERSION" } +uninstall_tala() { + uninstall_standalone_tala +} + +uninstall_standalone_tala() { + header "uninstalling standalone release d2plugin-tala-$INSTALLED_VERSION" + + if [ ! -e "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" ]; then + echoerr "missing standalone install release directory $INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + return 1 + fi + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + + "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" + "$sh_c" rm -rf "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" +} + is_prefix_writable() { sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true # The reason for checking whether bin is writable specifically is that on macOS you have diff --git a/ci/release/gen_install.sh b/ci/release/gen_install.sh index b04325cc2..1931d9029 100755 --- a/ci/release/gen_install.sh +++ b/ci/release/gen_install.sh @@ -1,6 +1,6 @@ #!/bin/sh set -eu -cd -- "$(dirname "$0")/../.." +cd -- "$(dirname "$0")/../.." . ./ci/sub/lib.sh cat >./install.sh </dev/null; then - echoerr "no version of d2 installed" - return 1 - fi - INSTALLED_VERSION="$(d2 version)" - if ! uninstall; then - echoerr "failed to uninstall $INSTALLED_VERSION" - return 1 - fi + uninstall return 0 fi @@ -583,24 +575,13 @@ main() { fetch_release_info fi - if command -v d2 >/dev/null; then - INSTALLED_VERSION="$(d2 version)" - if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then - log "skipping installation as version $VERSION is already installed." - return 0 - fi - log "uninstalling $INSTALLED_VERSION to install $VERSION" - if ! uninstall; then - warn "failed to uninstall $INSTALLED_VERSION" - fi - fi install } install() { - standalone_install + install_d2 if [ "${TALA-}" ]; then - standalone_install_tala + install_tala fi COLOR=2 header success @@ -617,14 +598,23 @@ EOF fi } -uninstall() { - standalone_uninstall - if [ "${TALA-}" ]; then - standalone_uninstall_tala +install_d2() { + if command -v d2 >/dev/null; then + INSTALLED_VERSION="$(d2 version)" + if [ ! "${FORCE-}" -a "$VERSION" = "$INSTALLED_VERSION" ]; then + log "skipping installation as version $VERSION is already installed." + return 0 + fi + log "uninstalling $INSTALLED_VERSION to install $VERSION" + if ! uninstall_d2; then + warn "failed to uninstall $INSTALLED_VERSION" + fi fi + + install_standalone_d2 } -standalone_install() { +install_standalone_d2() { ARCHIVE="d2-$VERSION-$OS-$ARCH.tar.gz" header "installing standalone release $ARCHIVE from github" @@ -642,11 +632,66 @@ standalone_install() { "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2-$VERSION\" && make install PREFIX=\"$PREFIX\"'" } -standalone_uninstall() { +install_tala() { + install_standalone_tala +} + +install_standalone_tala() { + REPO="${REPO_TALA:-terrastruct/TALA}" + VERSION=${TALA:-latest} + RELEASE_INFO= + fetch_release_info + + ARCHIVE="d2plugin-tala-$VERSION-$OS-$ARCH.tar.gz" + header "installing standalone release $ARCHIVE from github" + + asset_line=$(cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) + asset_url=$(sed -n $((asset_line-3))p "$RELEASE_INFO" | sed 's/^.*: "\(.*\)",$/\1/g') + + fetch_gh "$asset_url" "$CACHE_DIR/$ARCHIVE" 'application/octet-stream' + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + + "$sh_c" tar -C "$INSTALL_DIR" -xzf "$CACHE_DIR/$ARCHIVE" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" +} + +uninstall() { + if ! command -v d2 >/dev/null; then + echoerr "no version of d2 installed" + return 1 + fi + INSTALLED_VERSION="$(d2 --version)" + if ! uninstall_d2; then + echoerr "failed to uninstall $INSTALLED_VERSION" + return 1 + fi + if [ "${TALA-}" ]; then + if ! command -v d2plugin-tala >/dev/null; then + echoerr "no version of d2plugin-tala installed" + return 1 + fi + INSTALLED_VERSION="$(d2plugin-tala --version)" + if ! uninstall_tala; then + echoerr "failed to uninstall d2plugin-tala $INSTALLED_VERSION" + return 1 + fi + fi + return 0 +} + +uninstall_d2() { + uninstall_standalone_d2 +} + +uninstall_standalone_d2() { header "uninstalling standalone release d2-$INSTALLED_VERSION" if [ ! -e "$INSTALL_DIR/d2-$INSTALLED_VERSION" ]; then - echoerr "no installed release directory for d2-$INSTALLED_VERSION in $INSTALL_DIR/d2-$INSTALLED_VERSION" + echoerr "missing standalone install release directory $INSTALL_DIR/d2-$INSTALLED_VERSION" return 1 fi @@ -659,6 +704,27 @@ standalone_uninstall() { "$sh_c" rm -rf "$INSTALL_DIR/d2-$INSTALLED_VERSION" } +uninstall_tala() { + uninstall_standalone_tala +} + +uninstall_standalone_tala() { + header "uninstalling standalone release d2plugin-tala-$INSTALLED_VERSION" + + if [ ! -e "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" ]; then + echoerr "missing standalone install release directory $INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + return 1 + fi + + sh_c="sh_c" + if ! is_prefix_writable; then + sh_c="sudo_sh_c" + fi + + "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" + "$sh_c" rm -rf "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" +} + is_prefix_writable() { sh_c "mkdir -p '$INSTALL_DIR' 2>/dev/null" || true # The reason for checking whether bin is writable specifically is that on macOS you have From 81277e758905b4093ed4da3d54419330827313f0 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 04:10:40 -0800 Subject: [PATCH 27/33] install.sh: Improve structure and logging --- ci/release/_install.sh | 18 +++++++++++------- install.sh | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 170d9d798..594020129 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -162,6 +162,7 @@ main() { VERSION=${VERSION:-latest} if [ "$VERSION" = latest ]; then + header "fetching latest release info" fetch_release_info fi @@ -171,11 +172,12 @@ main() { install() { install_d2 if [ "${TALA-}" ]; then - install_tala + # Run in subshell to avoid overwriting VERSION. + ( install_tala ) fi COLOR=2 header success - log "Standalone release $ARCHIVE has been successfully installed into $PREFIX" + log "d2-$VERSION-$OS-$ARCH has been successfully installed into $PREFIX" if ! echo "$PATH" | grep -qF "$PREFIX/bin"; then logcat >&2 <&2 < Date: Mon, 14 Nov 2022 04:33:22 -0800 Subject: [PATCH 28/33] install.sh: d2plugin-tala -> tala --- ci/release/_install.sh | 18 +++++++++--------- install.sh | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 594020129..0d47be980 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -235,7 +235,7 @@ install_standalone_tala() { RELEASE_INFO= fetch_release_info - ARCHIVE="d2plugin-tala-$VERSION-$OS-$ARCH.tar.gz" + ARCHIVE="tala-$VERSION-$OS-$ARCH.tar.gz" log "installing standalone release $ARCHIVE from github" asset_line=$(cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) @@ -249,7 +249,7 @@ install_standalone_tala() { fi "$sh_c" tar -C "$INSTALL_DIR" -xzf "$CACHE_DIR/$ARCHIVE" - "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" } uninstall() { @@ -264,12 +264,12 @@ uninstall() { fi if [ "${TALA-}" ]; then if ! command -v d2plugin-tala >/dev/null; then - echoerr "no version of d2plugin-tala installed" + echoerr "no version of tala installed" return 1 fi INSTALLED_VERSION="$(d2plugin-tala --version)" if ! uninstall_tala; then - echoerr "failed to uninstall d2plugin-tala $INSTALLED_VERSION" + echoerr "failed to uninstall tala $INSTALLED_VERSION" return 1 fi fi @@ -303,10 +303,10 @@ uninstall_tala() { } uninstall_standalone_tala() { - log "uninstalling standalone release d2plugin-tala-$INSTALLED_VERSION" + log "uninstalling standalone release tala-$INSTALLED_VERSION" - if [ ! -e "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" ]; then - echoerr "missing standalone install release directory $INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + if [ ! -e "$INSTALL_DIR/tala-$INSTALLED_VERSION" ]; then + echoerr "missing standalone install release directory $INSTALL_DIR/tala-$INSTALLED_VERSION" return 1 fi @@ -315,8 +315,8 @@ uninstall_standalone_tala() { sh_c="sudo_sh_c" fi - "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" - "$sh_c" rm -rf "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" + "$sh_c" rm -rf "$INSTALL_DIR/tala-$INSTALLED_VERSION" } is_prefix_writable() { diff --git a/install.sh b/install.sh index b1d5459bb..7ca5d42f1 100755 --- a/install.sh +++ b/install.sh @@ -645,7 +645,7 @@ install_standalone_tala() { RELEASE_INFO= fetch_release_info - ARCHIVE="d2plugin-tala-$VERSION-$OS-$ARCH.tar.gz" + ARCHIVE="tala-$VERSION-$OS-$ARCH.tar.gz" log "installing standalone release $ARCHIVE from github" asset_line=$(cat "$RELEASE_INFO" | grep -n "$ARCHIVE" | cut -d: -f1 | head -n1) @@ -659,7 +659,7 @@ install_standalone_tala() { fi "$sh_c" tar -C "$INSTALL_DIR" -xzf "$CACHE_DIR/$ARCHIVE" - "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$VERSION\" && make install PREFIX=\"$PREFIX\"'" } uninstall() { @@ -674,12 +674,12 @@ uninstall() { fi if [ "${TALA-}" ]; then if ! command -v d2plugin-tala >/dev/null; then - echoerr "no version of d2plugin-tala installed" + echoerr "no version of tala installed" return 1 fi INSTALLED_VERSION="$(d2plugin-tala --version)" if ! uninstall_tala; then - echoerr "failed to uninstall d2plugin-tala $INSTALLED_VERSION" + echoerr "failed to uninstall tala $INSTALLED_VERSION" return 1 fi fi @@ -713,10 +713,10 @@ uninstall_tala() { } uninstall_standalone_tala() { - log "uninstalling standalone release d2plugin-tala-$INSTALLED_VERSION" + log "uninstalling standalone release tala-$INSTALLED_VERSION" - if [ ! -e "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" ]; then - echoerr "missing standalone install release directory $INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + if [ ! -e "$INSTALL_DIR/tala-$INSTALLED_VERSION" ]; then + echoerr "missing standalone install release directory $INSTALL_DIR/tala-$INSTALLED_VERSION" return 1 fi @@ -725,8 +725,8 @@ uninstall_standalone_tala() { sh_c="sudo_sh_c" fi - "$sh_c" sh -c "'cd \"$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" - "$sh_c" rm -rf "$INSTALL_DIR/d2plugin-tala-$INSTALLED_VERSION" + "$sh_c" sh -c "'cd \"$INSTALL_DIR/tala-$INSTALLED_VERSION\" && make uninstall PREFIX=\"$PREFIX\"'" + "$sh_c" rm -rf "$INSTALL_DIR/tala-$INSTALLED_VERSION" } is_prefix_writable() { From a025393b3678a8fdc99cabfabf67c090dbc23a86 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 05:37:11 -0800 Subject: [PATCH 29/33] ci/release: Use release.sh script in ci/sub --- ci/release/release.sh | 206 +------------------------------ ci/release/template/README.md.sh | 10 +- ci/sub | 2 +- 3 files changed, 8 insertions(+), 210 deletions(-) diff --git a/ci/release/release.sh b/ci/release/release.sh index 45850cd50..345f1a8a9 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -1,209 +1,5 @@ #!/bin/sh set -eu cd -- "$(dirname "$0")/../.." -. ./ci/sub/lib.sh -help() { - cat < - -$0 implements the D2 release process. - -Flags: - ---rebuild: Normally the release script will avoid rebuilding release assets if they - already exist but if you changed something and need to force rebuild, use - this flag. ---prerelease: Pass to mark the release on GitHub as a pre-release. For pre-releases the - version format should include a suffix like v0.0.99-alpha.1 - As well, for pre-releases the script will not overwrite changelogs/next.md - with changelogs/template.md and instead keep it the same as - changelogs/v0.0.99-alpha.1.md. This is because you want to maintain the - changelog entries for the eventual final release. ---dry-run: Print the commands that would be ran without executing them. ---skip-build: Skip the build in case you want to upload your own specific assets. - Mainly for testing and debugging. - -Process: - -Let's say you passed in v0.0.99 as the version: - -1. It creates branch v0.0.99 based on master if one does not already exist. - - It then checks it out. -2. It moves changelogs/next.md to changelogs/v0.0.99.md if there isn't already a - changelogs/v0.0.99.md. - - If the move occured, changelogs/next.md is replaced with changelogs/template.md. -3. If the current commit does not have a title of v0.0.99 then a new commit with said - title will be created with all uncommitted changes. - - If the current commit does, then the uncommitted changes will be amended to the commit. -4. It pushes branch v0.0.99 to origin. -5. It creates a v0.0.99 git tag if one does not already exist. - If one does, it ensures the v0.0.99 tag points to the current commit. - Then it pushes the tag to origin. -6. It creates a draft GitHub release for the tag if one does not already exist. - - It will also set the release notes to match changelogs/v0.0.99.md even - if the release already exists. -7. It creates a draft PR for branch v0.0.99 into master if one does not already exist. -8. It builds the release assets if they do not exist. - Pass --rebuild to force rebuilding all release assets. -9. It uploads the release assets overwriting any existing assets on the release. - -Only a draft release will be created so do not fret if something goes wrong. -You can just rerun the script again as it is fully idempotent. - -To complete the release, merge the release PR and then publish the draft release. - -Testing: - -For testing, change the origin remote to a private throwaway repository and push master to -it. Then the PR, tag and draft release will be generated against said throwaway -repository. - -Example: - $0 v0.0.99 -EOF -} - -main() { - while :; do - flag_parse "$@" - case "$FLAG" in - h|help) - help - return 0 - ;; - rebuild) - flag_noarg && shift "$FLAGSHIFT" - REBUILD=1 - ;; - prerelease) - flag_noarg && shift "$FLAGSHIFT" - PRERELEASE=1 - ;; - dry-run) - flag_noarg && shift "$FLAGSHIFT" - DRY_RUN=1 - ;; - skip-build) - flag_noarg && shift "$FLAGSHIFT" - SKIP_BUILD=1 - ;; - '') - shift "$FLAGSHIFT" - break - ;; - *) - flag_errusage "unrecognized flag $FLAGRAW" - ;; - esac - done - - if [ $# -ne 1 ]; then - flag_errusage "first argument must be release version like v0.0.99" - fi - VERSION="$1" - shift - - header '1_ensure_branch' && _1_ensure_branch - header '2_ensure_changelog' && _2_ensure_changelog - header '3_ensure_commit' && _3_ensure_commit - header '4_push_branch' && _4_push_branch - header '5_ensure_tag' && _5_ensure_tag - header '6_ensure_release' && _6_ensure_release - header '7_ensure_pr' && _7_ensure_pr - header '8_ensure_assets' && _8_ensure_assets - header '9_upload_assets' && _9_upload_assets - - COLOR=2 header 'final steps' - cat >&2 </dev/null 2>&1; then - sh_c git push -f origin "refs/heads/$VERSION" - else - sh_c git push -fu origin "refs/heads/$VERSION" - fi -} - -_5_ensure_tag() { - sh_c git tag --force -a "$VERSION" -m "$VERSION" - sh_c git push -f origin "refs/tags/$VERSION" -} - -_6_ensure_release() { - release_url="$(gh release view "$VERSION" --json=url '--template={{ .url }}' 2>/dev/null || true)" - if [ -n "$release_url" ]; then - release_url="$(sh_c gh release edit \ - --draft \ - --notes-file "./ci/release/changelogs/$VERSION.md" \ - ${PRERELEASE:+--prerelease} \ - "--title=$VERSION" \ - "$VERSION" | tee /dev/stderr)" - return 0 - fi - release_url="$(sh_c gh release create \ - --draft \ - --notes-file "./ci/release/changelogs/$VERSION.md" \ - ${PRERELEASE:+--prerelease} \ - "--title=$VERSION" \ - "$VERSION" | tee /dev/stderr)" -} - -_7_ensure_pr() { - # We do not use gh pr view as that includes closed PRs. - pr_url="$(gh pr list --head "$VERSION" --json=url '--template={{ range . }}{{ .url }}{{end}}')" - body="Will be available at $(gh repo view --json=url '--template={{ .url }}')/releases/tag/$VERSION" - if [ -n "$pr_url" ]; then - sh_c gh pr edit --body "$body" "$VERSION" - return 0 - fi - - pr_url="$(sh_c gh pr create --fill --body "'$body'" | tee /dev/stderr)" -} - -_8_ensure_assets() { - if [ "${SKIP_BUILD-}" ]; then - warn "skipping building of assets due to --skip-build" - return 0 - fi - sh_c ./ci/release/build.sh ${REBUILD:+--rebuild} -} - -_9_upload_assets() { - ./ci/release/upload_assets.sh $VERSION -} - -main "$@" +./ci/sub/bin/release.sh "$@" diff --git a/ci/release/template/README.md.sh b/ci/release/template/README.md.sh index 880483016..ec7cb8a11 100755 --- a/ci/release/template/README.md.sh +++ b/ci/release/template/README.md.sh @@ -11,16 +11,18 @@ version: $VERSION ## Install \`\`\`sh -make install PREFIX=/usr/local DRY_RUN=1 +make install DRY_RUN=1 # If it looks right, run: -make install PREFIX=/usr/local +make install \`\`\` +Pass \`PREFIX=whatever\` to change the installation prefix. + ## Uninstall \`\`\`sh -make uninstall PREFIX=/usr/local DRY_RUN=1 +make uninstall DRY_RUN=1 # If it looks right, run: -make uninstall PREFIX=/usr/local +make uninstall \`\`\` EOF diff --git a/ci/sub b/ci/sub index 5a1c8e5e3..c91c28cbc 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 5a1c8e5e36a0b0c4b0d5e2ad4e08c3c815dd4bea +Subproject commit c91c28cbcaa8935c4054d7d5f0c28348caed5a2e From 0cf7f7ee9ce5845b9aeaa032d28a75850cc7e25f Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 05:50:17 -0800 Subject: [PATCH 30/33] ci/release: More fixes --- ci/release/README.md | 4 ---- ci/release/_install.sh | 2 +- ci/release/release.sh | 2 +- ci/release/upload_assets.sh | 47 ------------------------------------- ci/sub | 2 +- 5 files changed, 3 insertions(+), 54 deletions(-) delete mode 100755 ci/release/upload_assets.sh diff --git a/ci/release/README.md b/ci/release/README.md index 10c4c44b2..4530983e4 100644 --- a/ci/release/README.md +++ b/ci/release/README.md @@ -14,10 +14,6 @@ it depends on from ../sub/lib. - ./release.sh is the top level script to generate a new release. Run with --help for usage. -### upload_assets.sh - -- Called by ./release.sh to upload the assets for the release in $VERSION - ## build.sh - ./build.sh builds the release archives for each platform into ./build//*.tar.gz diff --git a/ci/release/_install.sh b/ci/release/_install.sh index 0d47be980..4637489f0 100755 --- a/ci/release/_install.sh +++ b/ci/release/_install.sh @@ -344,7 +344,7 @@ fetch_release_info() { return 0 fi - log "fetching info on version $VERSION" + log "fetching info on $VERSION version of $REPO" RELEASE_INFO=$(mktemp -d)/release-info.json if [ "$VERSION" = latest ]; then release_info_url="https://api.github.com/repos/$REPO/releases/$VERSION" diff --git a/ci/release/release.sh b/ci/release/release.sh index 345f1a8a9..517ae778d 100755 --- a/ci/release/release.sh +++ b/ci/release/release.sh @@ -2,4 +2,4 @@ set -eu cd -- "$(dirname "$0")/../.." -./ci/sub/bin/release.sh "$@" +./ci/sub/release/release.sh "$@" diff --git a/ci/release/upload_assets.sh b/ci/release/upload_assets.sh deleted file mode 100755 index f14da46b6..000000000 --- a/ci/release/upload_assets.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/sh -set -eu -cd -- "$(dirname "$0")/../.." -. ./ci/sub/lib.sh - -help() { - cat < - -Uploads the assets for release to GitHub. - -For example, if is v0.0.99 then it uploads files matching -./ci/release/build/v0.0.99/*.tar.gz to the GitHub release v0.0.99. - -Example: - $0 v0.0.99 -EOF -} - -main() { - while :; do - flag_parse "$@" - case "$FLAG" in - h|help) - help - return 0 - ;; - '') - shift "$FLAGSHIFT" - break - ;; - *) - flag_errusage "unrecognized flag $FLAGRAW" - ;; - esac - done - - if [ $# -ne 1 ]; then - flag_errusage "first argument must be release version like v0.0.99" - fi - VERSION="$1" - shift - - sh_c gh release upload --clobber "$VERSION" "./ci/release/build/$VERSION"/*.tar.gz -} - -main "$@" diff --git a/ci/sub b/ci/sub index c91c28cbc..231dec909 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit c91c28cbcaa8935c4054d7d5f0c28348caed5a2e +Subproject commit 231dec9096304f1a033fd2ef35228d4c6e0744b3 From d13f4a8935da900bdcf6ec3cb4211bf4fcd3a36e Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 06:57:01 -0800 Subject: [PATCH 31/33] ci/release: More fixes --- ci/release/build.sh | 38 +++++++++++-- ci/release/builders/ensure_aws.sh | 95 ++++++++++++++++++++++++++++--- ci/sub | 2 +- 3 files changed, 121 insertions(+), 14 deletions(-) diff --git a/ci/release/build.sh b/ci/release/build.sh index 8aaec7c93..fed37c716 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -115,18 +115,30 @@ build() { fi case $OS in - # macos) - # ;; + macos) + case $ARCH in + amd64) + RHOST=$TSTRUCT_MACOS_AMD64_BUILDER build_rhost_macos + ;; + arm64) + RHOST=$TSTRUCT_MACOS_ARM64_BUILDER build_rhost_macos + ;; + *) + warn "no builder for OS=$OS ARCH=$ARCH, building locally..." + build_local + ;; + esac + ;; linux) case $ARCH in amd64) - RHOST=$TSTRUCT_LINUX_AMD64_BUILDER build_rhost + RHOST=$TSTRUCT_LINUX_AMD64_BUILDER build_rhost_linux ;; arm64) - RHOST=$TSTRUCT_LINUX_ARM64_BUILDER build_rhost + RHOST=$TSTRUCT_LINUX_ARM64_BUILDER build_rhost_linux ;; *) - warn "no builder for OS=$OS, building locally..." + warn "no builder for OS=$OS ARCH=$ARCH, building locally..." build_local ;; esac @@ -148,7 +160,21 @@ build_local() { sh_c ./ci/release/_build.sh } -build_rhost() { +build_rhost_macos() { + sh_c ssh "$RHOST" mkdir -p src + sh_c rsync --archive --human-readable --delete ./ "$RHOST:src/d2/" + sh_c ssh -tttt "$RHOST" "DRY_RUN=${DRY_RUN-} \ +HW_BUILD_DIR=$HW_BUILD_DIR \ +VERSION=$VERSION \ +OS=$OS \ +ARCH=$ARCH \ +ARCHIVE=$ARCHIVE \ +TERM=$TERM \ +./src/d2/ci/release/_build.sh" + sh_c rsync --archive --human-readable "$RHOST:src/d2/$ARCHIVE" "$ARCHIVE" +} + +build_rhost_linux() { sh_c ssh "$RHOST" mkdir -p src sh_c rsync --archive --human-readable --delete ./ "$RHOST:src/d2/" sh_c ssh -tttt "$RHOST" "DRY_RUN=${DRY_RUN-} \ diff --git a/ci/release/builders/ensure_aws.sh b/ci/release/builders/ensure_aws.sh index 9e4c35a53..3fa4da5c3 100755 --- a/ci/release/builders/ensure_aws.sh +++ b/ci/release/builders/ensure_aws.sh @@ -75,8 +75,8 @@ create_rhosts() { --instance-type=t2.small \ --security-groups=ssh \ "--key-name=$KEY_NAME" \ - --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' \ - 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]' >/dev/null + --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]"' \ + '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-amd64}]"' >/dev/null fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ @@ -100,8 +100,8 @@ create_rhosts() { --instance-type=t4g.small \ --security-groups=ssh \ "--key-name=$KEY_NAME" \ - --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' \ - 'ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]' >/dev/null + --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]"' \ + '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-linux-arm64}]"' >/dev/null fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ @@ -114,18 +114,86 @@ create_rhosts() { fi sleep 5 done + + header "allocate macOS hosts" + if ! aws ec2 describe-hosts | grep -q mac1.metal; then + aws ec2 allocate-hosts --instance-type mac1.metal --quantity 1 --availability-zone us-west-2a + fi + if ! aws ec2 describe-hosts | grep -q mac2.metal; then + aws ec2 allocate-hosts --instance-type mac2.metal --quantity 1 --availability-zone us-west-2a + fi + + header macos-amd64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-macos-amd64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0dd2ded7568750663 \ + --count=1 \ + --instance-type=mac1.metal \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --placement 'Tenancy=host,HostId=h-0d881926de2e17555' \ + --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' \ + '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' >/dev/null + fi + while true; do + dnsname=$(sh_c aws ec2 describe-instances \ + --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-amd64' \ + | jq -r '.Reservations[].Instances[].PublicDnsName') + if [ -n "$dnsname" ]; then + log "TSTRUCT_MACOS_AMD64_BUILDER=ec2-user@$dnsname" + export TSTRUCT_MACOS_AMD64_BUILDER=ec2-user@$dnsname + break + fi + sleep 5 + done + + header macos-arm64 + if ! aws ec2 describe-instances \ + "--query=Reservations[*].Instances[?State.Name!='terminated']" \ + | grep -q d2-builder-macos-arm64; then + sh_c aws ec2 run-instances \ + --image-id=ami-0af0516ff2c43dbbe \ + --count=1 \ + --instance-type=mac2.metal \ + --security-groups=ssh \ + "--key-name=$KEY_NAME" \ + --placement 'Tenancy=host,HostId=h-040b9305c2d64119d' \ + --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-macos-arm64}]"' \ + '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-macos-arm64}]"' >/dev/null + fi + while true; do + dnsname=$(sh_c aws ec2 describe-instances \ + --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-arm64' \ + | jq -r '.Reservations[].Instances[].PublicDnsName') + if [ -n "$dnsname" ]; then + log "TSTRUCT_MACOS_ARM64_BUILDER=ec2-user@$dnsname" + export TSTRUCT_MACOS_ARM64_BUILDER=ec2-user@$dnsname + break + fi + sleep 5 + done } init_rhosts() { header linux-amd64 - RHOST=$TSTRUCT_LINUX_AMD64_BUILDER init_rhost + RHOST=$TSTRUCT_LINUX_AMD64_BUILDER init_rhost_linux header linux-arm64 - RHOST=$TSTRUCT_LINUX_ARM64_BUILDER init_rhost + RHOST=$TSTRUCT_LINUX_ARM64_BUILDER init_rhost_linux + header macos-amd64 + RHOST=$TSTRUCT_MACOS_AMD64_BUILDER init_rhost_macos + header macos-arm64 + RHOST=$TSTRUCT_MACOS_ARM64_BUILDER init_rhost_macos + + COLOR=2 header summary log "export TSTRUCT_LINUX_AMD64_BUILDER=$TSTRUCT_LINUX_AMD64_BUILDER" log "export TSTRUCT_LINUX_ARM64_BUILDER=$TSTRUCT_LINUX_ARM64_BUILDER" + log "export TSTRUCT_MACOS_AMD64_BUILDER=$TSTRUCT_MACOS_AMD64_BUILDER" + log "export TSTRUCT_MACOS_ARM64_BUILDER=$TSTRUCT_MACOS_ARM64_BUILDER" } -init_rhost() { +init_rhost_linux() { while true; do if sh_c ssh "$RHOST" :; then break @@ -140,4 +208,17 @@ init_rhost() { sh_c ssh "$RHOST" 'sudo reboot' || true } +init_rhost_macos() { + while true; do + if sh_c ssh "$RHOST" :; then + break + fi + sleep 5 + done + sh_c ssh "$RHOST" '": | /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""' + sh_c ssh "$RHOST" 'brew update' + sh_c ssh "$RHOST" 'brew upgrade' + sh_c ssh "$RHOST" 'brew install go' +} + main "$@" diff --git a/ci/sub b/ci/sub index 231dec909..be28ce747 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 231dec9096304f1a033fd2ef35228d4c6e0744b3 +Subproject commit be28ce747b280c59b8fe89e6b29bb0637984985d From d22702c96be8418fd705ade641cedf36d72d4b0f Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Mon, 14 Nov 2022 10:26:37 -0800 Subject: [PATCH 32/33] ci/release: Many bug fixes and add manpage Closes #86 Closes #85 --- ci/release/build.sh | 1 + .../builders/{ensure_aws.sh => aws_ensure.sh} | 64 +++++++++++-------- ci/release/builders/aws_ssh_copy_id.sh | 43 +++++++++++++ ci/release/template/man/d2.1 | 62 ++++++++++++++++++ ci/release/template/scripts/install.sh | 1 + ci/release/template/scripts/uninstall.sh | 1 + install.sh | 6 +- 7 files changed, 151 insertions(+), 27 deletions(-) rename ci/release/builders/{ensure_aws.sh => aws_ensure.sh} (69%) create mode 100755 ci/release/builders/aws_ssh_copy_id.sh create mode 100644 ci/release/template/man/d2.1 diff --git a/ci/release/build.sh b/ci/release/build.sh index fed37c716..be40bd835 100755 --- a/ci/release/build.sh +++ b/ci/release/build.sh @@ -170,6 +170,7 @@ OS=$OS \ ARCH=$ARCH \ ARCHIVE=$ARCHIVE \ TERM=$TERM \ +PATH=\"/usr/local/bin:/usr/local/sbin\${PATH+:\$PATH}\" \ ./src/d2/ci/release/_build.sh" sh_c rsync --archive --human-readable "$RHOST:src/d2/$ARCHIVE" "$ARCHIVE" } diff --git a/ci/release/builders/ensure_aws.sh b/ci/release/builders/aws_ensure.sh similarity index 69% rename from ci/release/builders/ensure_aws.sh rename to ci/release/builders/aws_ensure.sh index 3fa4da5c3..d1b1a531c 100755 --- a/ci/release/builders/ensure_aws.sh +++ b/ci/release/builders/aws_ensure.sh @@ -66,9 +66,10 @@ create_rhosts() { fi header linux-amd64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-linux-amd64; then + state=$(aws ec2 describe-instances --filters \ + 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-amd64' \ + | jq -r '.Reservations[].Instances[].State.Name') + if [ -z "$state" ]; then sh_c aws ec2 run-instances \ --image-id=ami-0d593311db5abb72b \ --count=1 \ @@ -80,7 +81,7 @@ create_rhosts() { fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ - --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-amd64' \ + --filters 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-amd64' \ | jq -r '.Reservations[].Instances[].PublicDnsName') if [ -n "$dnsname" ]; then log "TSTRUCT_LINUX_AMD64_BUILDER=ec2-user@$dnsname" @@ -91,9 +92,10 @@ create_rhosts() { done header linux-arm64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-linux-arm64; then + state=$(aws ec2 describe-instances --filters \ + 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-arm64' \ + | jq -r '.Reservations[].Instances[].State.Name') + if [ -z "$state" ]; then sh_c aws ec2 run-instances \ --image-id=ami-0efabcf945ffd8831 \ --count=1 \ @@ -105,7 +107,7 @@ create_rhosts() { fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ - --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-arm64' \ + --filters 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-linux-arm64' \ | jq -r '.Reservations[].Instances[].PublicDnsName') if [ -n "$dnsname" ]; then log "TSTRUCT_LINUX_ARM64_BUILDER=ec2-user@$dnsname" @@ -115,31 +117,40 @@ create_rhosts() { sleep 5 done - header "allocate macOS hosts" - if ! aws ec2 describe-hosts | grep -q mac1.metal; then - aws ec2 allocate-hosts --instance-type mac1.metal --quantity 1 --availability-zone us-west-2a + header "macos-amd64-host" + MACOS_AMD64_HOST_ID=$(aws ec2 describe-hosts --filter 'Name=state,Values=pending,available' 'Name=tag:Name,Values=d2-builder-macos-amd64' | jq -r '.Hosts[].HostId') + if [ -z "$MACOS_AMD64_HOST_ID" ]; then + MACOS_AMD64_HOST_ID=$(sh_c aws ec2 allocate-hosts --instance-type mac1.metal --quantity 1 --availability-zone us-west-2a \ + --tag-specifications '"ResourceType=dedicated-host,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' \ + | jq -r .HostIds[0]) fi - if ! aws ec2 describe-hosts | grep -q mac2.metal; then - aws ec2 allocate-hosts --instance-type mac2.metal --quantity 1 --availability-zone us-west-2a + + header "macos-arm64-host" + MACOS_ARM64_HOST_ID=$(aws ec2 describe-hosts --filter 'Name=state,Values=pending,available' 'Name=tag:Name,Values=d2-builder-macos-arm64' | jq -r '.Hosts[].HostId') + if [ -z "$MACOS_ARM64_HOST_ID" ]; then + MACOS_ARM64_HOST_ID=$(sh_c aws ec2 allocate-hosts --instance-type mac2.metal --quantity 1 --availability-zone us-west-2a \ + --tag-specifications '"ResourceType=dedicated-host,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' \ + | jq -r .HostIds[0]) fi header macos-amd64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-macos-amd64; then + state=$(aws ec2 describe-instances --filters \ + 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-amd64' \ + | jq -r '.Reservations[].Instances[].State.Name') + if [ -z "$state" ]; then sh_c aws ec2 run-instances \ --image-id=ami-0dd2ded7568750663 \ --count=1 \ --instance-type=mac1.metal \ --security-groups=ssh \ "--key-name=$KEY_NAME" \ - --placement 'Tenancy=host,HostId=h-0d881926de2e17555' \ + --placement "Tenancy=host,HostId=$MACOS_AMD64_HOST_ID" \ --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' \ '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-macos-amd64}]"' >/dev/null fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ - --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-amd64' \ + --filters 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-amd64' \ | jq -r '.Reservations[].Instances[].PublicDnsName') if [ -n "$dnsname" ]; then log "TSTRUCT_MACOS_AMD64_BUILDER=ec2-user@$dnsname" @@ -150,22 +161,23 @@ create_rhosts() { done header macos-arm64 - if ! aws ec2 describe-instances \ - "--query=Reservations[*].Instances[?State.Name!='terminated']" \ - | grep -q d2-builder-macos-arm64; then + state=$(aws ec2 describe-instances --filters \ + 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-arm64' \ + | jq -r '.Reservations[].Instances[].State.Name') + if [ -z "$state" ]; then sh_c aws ec2 run-instances \ --image-id=ami-0af0516ff2c43dbbe \ --count=1 \ --instance-type=mac2.metal \ --security-groups=ssh \ "--key-name=$KEY_NAME" \ - --placement 'Tenancy=host,HostId=h-040b9305c2d64119d' \ + --placement "Tenancy=host,HostId=$MACOS_ARM64_HOST_ID" \ --tag-specifications '"ResourceType=instance,Tags=[{Key=Name,Value=d2-builder-macos-arm64}]"' \ '"ResourceType=volume,Tags=[{Key=Name,Value=d2-builder-macos-arm64}]"' >/dev/null fi while true; do dnsname=$(sh_c aws ec2 describe-instances \ - --filters 'Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-arm64' \ + --filters 'Name=instance-state-name,Values=pending,running,stopping,stopped' 'Name=tag:Name,Values=d2-builder-macos-arm64' \ | jq -r '.Reservations[].Instances[].PublicDnsName') if [ -n "$dnsname" ]; then log "TSTRUCT_MACOS_ARM64_BUILDER=ec2-user@$dnsname" @@ -216,9 +228,9 @@ init_rhost_macos() { sleep 5 done sh_c ssh "$RHOST" '": | /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""' - sh_c ssh "$RHOST" 'brew update' - sh_c ssh "$RHOST" 'brew upgrade' - sh_c ssh "$RHOST" 'brew install go' + sh_c ssh "$RHOST" '/usr/local/bin/brew update' + sh_c ssh "$RHOST" '/usr/local/bin/brew upgrade' + sh_c ssh "$RHOST" '/usr/local/bin/brew install go' } main "$@" diff --git a/ci/release/builders/aws_ssh_copy_id.sh b/ci/release/builders/aws_ssh_copy_id.sh new file mode 100755 index 000000000..d50a96d9d --- /dev/null +++ b/ci/release/builders/aws_ssh_copy_id.sh @@ -0,0 +1,43 @@ +#!/bin/sh +set -eu +cd -- "$(dirname "$0")/../../.." +. ./ci/sub/lib.sh + +help() { + cat < Date: Mon, 14 Nov 2022 11:08:23 -0800 Subject: [PATCH 33/33] release: gitignore --- ci/release/build/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 ci/release/build/.gitignore diff --git a/ci/release/build/.gitignore b/ci/release/build/.gitignore new file mode 100644 index 000000000..72e8ffc0d --- /dev/null +++ b/ci/release/build/.gitignore @@ -0,0 +1 @@ +*