From 8a41a6bb5b0aa8c685a932f2d3cb90780fb1778e Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Sun, 24 Jul 2022 22:16:16 -0700 Subject: [PATCH] Fix snap publishing flow, publish assets independently --- .circleci/config.yml | 71 +++++++++++++++---- .circleci/template.yml | 71 +++++++++++++++---- ...ild-bundle.sh => build-appimage-bundle.sh} | 23 ------ scripts/build-arch-bundle | 46 ++++++++++++ ...ish-release.sh => publish-arch-release.sh} | 14 ++++ 5 files changed, 172 insertions(+), 53 deletions(-) rename scripts/{build-bundle.sh => build-appimage-bundle.sh} (52%) create mode 100755 scripts/build-arch-bundle rename scripts/{publish-release.sh => publish-arch-release.sh} (92%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7d468af56..aded1f423 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -115,7 +115,7 @@ jobs: command: | git --no-pager diff go.mod go.sum git --no-pager diff --quiet go.mod go.sum - build-all: + build-linux: executor: golang steps: - install-deps @@ -518,6 +518,19 @@ jobs: publish: description: publish binary artifacts executor: ubuntu + parameters: + linux: + default: false + description: publish linux binaries? + type: boolean + darwin: + default: false + description: publish darwin binaries? + type: boolean + appimage: + default: false + description: publish appimage binaries? + type: boolean steps: - run: name: Install git jq curl @@ -528,12 +541,21 @@ jobs: - install_ipfs - attach_workspace: at: "." - - run: - name: Create bundles - command: ./scripts/build-bundle.sh - - run: - name: Publish release - command: ./scripts/publish-release.sh + - when: + condition: << parameters.linux >> + steps: + - run: ./scripts/build-arch-bundle.sh linux + - run: ./scripts/publish-arch-release.sh linux + - when: + condition: << parameters.darwin>> + steps: + - run: ./scripts/build-arch-bundle.sh darwin + - run: ./scripts/publish-arch-release.sh darwin + - when: + condition: << parameters.appimage >> + steps: + - run: ./scripts/build-appimage-bundle.sh + - run: ./scripts/publish-arch-release.sh appimage publish-snapcraft: description: build and push snapcraft @@ -550,11 +572,6 @@ jobs: - run: name: install snapcraft command: sudo snap install snapcraft --classic - - run: - name: create snapcraft config file - command: | - mkdir -p ~/.config/snapcraft - echo "$SNAPCRAFT_LOGIN_FILE" | base64 -d > ~/.config/snapcraft/snapcraft.cfg - run: name: build snap command: snapcraft --use-lxd @@ -1020,7 +1037,7 @@ workflows: only: - master - build-debug - - build-all: + - build-linux: filters: tags: only: @@ -1042,6 +1059,18 @@ workflows: only: - /^v\d+\.\d+\.\d+(-rc\d+)?$/ - build-appimage: + filters: + branches: + only: + - /^release\/v\d+\.\d+\.\d+(-rc\d+)?$/ + tags: + only: + - /^v\d+\.\d+\.\d+(-rc\d+)?$/ + - publish: + name: publish-macos + darwin: true + requires: + - build-macos filters: branches: ignore: @@ -1050,9 +1079,21 @@ workflows: only: - /^v\d+\.\d+\.\d+(-rc\d+)?$/ - publish: + name: publish-linux + linux: true + requires: + - build-linux + filters: + branches: + ignore: + - /.*/ + tags: + only: + - /^v\d+\.\d+\.\d+(-rc\d+)?$/ + - publish: + name: publish-appimage + appimage: true requires: - - build-all - - build-macos - build-appimage filters: branches: diff --git a/.circleci/template.yml b/.circleci/template.yml index fb2497a1e..82db7ae81 100644 --- a/.circleci/template.yml +++ b/.circleci/template.yml @@ -115,7 +115,7 @@ jobs: command: | git --no-pager diff go.mod go.sum git --no-pager diff --quiet go.mod go.sum - build-all: + build-linux: executor: golang steps: - install-deps @@ -518,6 +518,19 @@ jobs: publish: description: publish binary artifacts executor: ubuntu + parameters: + linux: + default: false + description: publish linux binaries? + type: boolean + darwin: + default: false + description: publish darwin binaries? + type: boolean + appimage: + default: false + description: publish appimage binaries? + type: boolean steps: - run: name: Install git jq curl @@ -528,12 +541,21 @@ jobs: - install_ipfs - attach_workspace: at: "." - - run: - name: Create bundles - command: ./scripts/build-bundle.sh - - run: - name: Publish release - command: ./scripts/publish-release.sh + - when: + condition: << parameters.linux >> + steps: + - run: ./scripts/build-arch-bundle.sh linux + - run: ./scripts/publish-arch-release.sh linux + - when: + condition: << parameters.darwin>> + steps: + - run: ./scripts/build-arch-bundle.sh darwin + - run: ./scripts/publish-arch-release.sh darwin + - when: + condition: << parameters.appimage >> + steps: + - run: ./scripts/build-appimage-bundle.sh + - run: ./scripts/publish-arch-release.sh appimage publish-snapcraft: description: build and push snapcraft @@ -550,11 +572,6 @@ jobs: - run: name: install snapcraft command: sudo snap install snapcraft --classic - - run: - name: create snapcraft config file - command: | - mkdir -p ~/.config/snapcraft - echo "$SNAPCRAFT_LOGIN_FILE" | base64 -d > ~/.config/snapcraft/snapcraft.cfg - run: name: build snap command: snapcraft --use-lxd @@ -780,7 +797,7 @@ workflows: only: - master - build-debug - - build-all: + - build-linux: filters: tags: only: @@ -802,6 +819,18 @@ workflows: only: - /^v\d+\.\d+\.\d+(-rc\d+)?$/ - build-appimage: + filters: + branches: + only: + - /^release\/v\d+\.\d+\.\d+(-rc\d+)?$/ + tags: + only: + - /^v\d+\.\d+\.\d+(-rc\d+)?$/ + - publish: + name: publish-macos + darwin: true + requires: + - build-macos filters: branches: ignore: @@ -810,9 +839,21 @@ workflows: only: - /^v\d+\.\d+\.\d+(-rc\d+)?$/ - publish: + name: publish-linux + linux: true + requires: + - build-linux + filters: + branches: + ignore: + - /.*/ + tags: + only: + - /^v\d+\.\d+\.\d+(-rc\d+)?$/ + - publish: + name: publish-appimage + appimage: true requires: - - build-all - - build-macos - build-appimage filters: branches: diff --git a/scripts/build-bundle.sh b/scripts/build-appimage-bundle.sh similarity index 52% rename from scripts/build-bundle.sh rename to scripts/build-appimage-bundle.sh index fe1c88611..0d6f8ab40 100755 --- a/scripts/build-bundle.sh +++ b/scripts/build-appimage-bundle.sh @@ -1,11 +1,6 @@ #!/usr/bin/env bash set -ex -ARCHS=( - "darwin" - "linux" -) - REQUIRED=( "ipfs" "sha512sum" @@ -31,24 +26,6 @@ PID="$!" trap "kill -9 ${PID}" EXIT sleep 30 -for ARCH in "${ARCHS[@]}" -do - mkdir -p "${ARCH}/lotus" - pushd "${ARCH}" - for BINARY in "${BINARIES[@]}" - do - cp "../../${ARCH}/${BINARY}" "lotus/" - chmod +x "lotus/${BINARY}" - done - - tar -zcvf "../lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" lotus - popd - rm -rf "${ARCH}" - - sha512sum "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" > "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz.sha512" - - ipfs add -q "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" > "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz.cid" -done cp "../appimage/Lotus-${CIRCLE_TAG}-x86_64.AppImage" . sha512sum "Lotus-${CIRCLE_TAG}-x86_64.AppImage" > "Lotus-${CIRCLE_TAG}-x86_64.AppImage.sha512" ipfs add -q "Lotus-${CIRCLE_TAG}-x86_64.AppImage" > "Lotus-${CIRCLE_TAG}-x86_64.AppImage.cid" diff --git a/scripts/build-arch-bundle b/scripts/build-arch-bundle new file mode 100755 index 000000000..27b4218f5 --- /dev/null +++ b/scripts/build-arch-bundle @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -ex + +ARCH=$1 + +REQUIRED=( + "ipfs" + "sha512sum" +) +for REQUIRE in "${REQUIRED[@]}" +do + command -v "${REQUIRE}" >/dev/null 2>&1 || echo >&2 "'${REQUIRE}' must be installed" +done + +mkdir bundle +pushd bundle + +BINARIES=( + "lotus" + "lotus-miner" + "lotus-worker" +) + +export IPFS_PATH=`mktemp -d` +ipfs init +ipfs daemon & +PID="$!" +trap "kill -9 ${PID}" EXIT +sleep 30 + +mkdir -p "${ARCH}/lotus" +pushd "${ARCH}" +for BINARY in "${BINARIES[@]}" +do + cp "../../${ARCH}/${BINARY}" "lotus/" + chmod +x "lotus/${BINARY}" +done + +tar -zcvf "../lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" lotus +popd +rm -rf "${ARCH}" + +sha512sum "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" > "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz.sha512" + +ipfs add -q "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz" > "lotus_${CIRCLE_TAG}_${ARCH}-amd64.tar.gz.cid" +popd diff --git a/scripts/publish-release.sh b/scripts/publish-arch-release.sh similarity index 92% rename from scripts/publish-release.sh rename to scripts/publish-arch-release.sh index 22572de60..b47ad53fe 100755 --- a/scripts/publish-release.sh +++ b/scripts/publish-arch-release.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e +ARCH=$1 + pushd bundle # make sure we have a token set, api requests won't work otherwise @@ -61,23 +63,35 @@ fi RELEASE_UPLOAD_URL=`echo "${RELEASE_RESPONSE}" | jq -r '.upload_url' | cut -d'{' -f1` echo "Preparing to send artifacts to ${RELEASE_UPLOAD_URL}" +if [ $ARCH = 'linux' ]; then artifacts=( "lotus_${CIRCLE_TAG}_linux-amd64.tar.gz" "lotus_${CIRCLE_TAG}_linux-amd64.tar.gz.cid" "lotus_${CIRCLE_TAG}_linux-amd64.tar.gz.sha512" +) +elif [ $ARCH = 'darwin' ]; then +artifacts=( "lotus_${CIRCLE_TAG}_darwin-amd64.tar.gz" "lotus_${CIRCLE_TAG}_darwin-amd64.tar.gz.cid" "lotus_${CIRCLE_TAG}_darwin-amd64.tar.gz.sha512" +) +elif [ $ARCH = 'appimage' ]; then +artifacts=( "Lotus-${CIRCLE_TAG}-x86_64.AppImage" "Lotus-${CIRCLE_TAG}-x86_64.AppImage.cid" "Lotus-${CIRCLE_TAG}-x86_64.AppImage.sha512" ) +else + echo "$1 is not a supported architecture to publish a release for" 1>&2 + exit 1 +fi for RELEASE_FILE in "${artifacts[@]}" do echo "Uploading ${RELEASE_FILE}..." curl \ --request POST \ + --fail \ --header "Authorization: token ${GITHUB_TOKEN}" \ --header "Content-Type: application/octet-stream" \ --data-binary "@${RELEASE_FILE}" \