From 2a66855fc2548ea5a0281ff92c03735958968fcb Mon Sep 17 00:00:00 2001 From: Leo Covarrubias Date: Sun, 23 Oct 2022 15:09:06 -0400 Subject: [PATCH] update workflow scripts --- .github/workflows/ci.yml | 97 +++++++++++------------------------ .github/workflows/release.yml | 34 ++++++++++++ scripts/release.sh | 80 +++++++++++++++++++---------- 3 files changed, 116 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f87b27..2c186a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,92 +1,53 @@ name: ci on: - push: - branches: - - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ pull_request: jobs: format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 with: - go-version: 1.19 - - name: Format Test + go-version-file: './go.mod' + cache: true + + - name: Check Go Format run: make fmtcheck test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 with: - go-version: 1.19 - - name: Tests + go-version-file: './go.mod' + cache: true + + - name: Run Tests run: make test build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Branch Info - id: branch_info - run: echo ::set-output name=TAG::${GITHUB_REF#refs/tags/} - - uses: actions/cache@v2 - with: - path: ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - uses: actions/setup-go@v2 + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 with: - go-version: 1.19 - - name: Deps + go-version-file: './go.mod' + cache: true + + - name: Install GOX run: go install github.com/mitchellh/gox@latest - - name: Build - run: env RELEASE_TAG=${{ steps.branch_info.outputs.TAG }} make release - - name: Build Files - run: ls ${{ github.workspace }}/dist - - uses: actions/cache@v2 - with: - path: ${{ github.workspace }}/dist - key: build-go-${{ hashFiles('**/*.sha256') }} - restore-keys: | - build-go- - release: - needs: - - format - - test - - build - if: startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - steps: - - uses: actions/cache@v2 - with: - path: ${{ github.workspace }}/dist - key: build-go-${{ hashFiles('**/*.sha256') }} - restore-keys: | - build-go- - - name: List Files - run: ls ${{ github.workspace }}/dist - - name: Release - uses: softprops/action-gh-release@v1 - with: - files: ${{ github.workspace }}/dist/* - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Multi-target Build + run: make release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e8d9730 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: release + +on: + release: + types: [created] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version-file: "${{ github.workspace }}/go.mod" + cache: true + + - name: Install GOX + run: go install github.com/mitchellh/gox@latest + + - name: Multi-target Build + run: RELEASE_TAG=${GITHUB_REF#refs/tags/} make release + + - name: List Files + run: ls ${{ github.workspace }}/dist + + - name: Push Files + uses: softprops/action-gh-release@v1 + with: + files: ${{ github.workspace }}/dist/* + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/scripts/release.sh b/scripts/release.sh index 932fdde..437cb4a 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -23,12 +23,13 @@ XC_ARCH=${XC_ARCH:-"arm arm64 amd64"} XC_OS=${XC_OS:-"linux darwin windows"} XC_EXCLUDE_OSARCH="!darwin/arm !windows/arm" -# Delete the old dir -echo -echo "==> Removing old directory..." -rm -rf bin/* -mkdir -p bin/ -rm -rf dist/* +if [[ -d ./bin || -d ./dist ]]; then + echo + echo "==> Clearing Old Builds..." + rm -rf bin/* + rm -rf dist/* +fi + mkdir -p dist/ if ! command -v gox >/dev/null; then @@ -51,42 +52,67 @@ echo echo "==> Building..." echo "ldflags: ${LD_FLAGS}" -BIN_NAME=${PWD##*/} -BUILD_PREFIX="${BIN_NAME}-" +BIN_NAME="tadpoles-backup" +BUILD_PREFIX="${BIN_NAME}" gox \ -os="${XC_OS}" \ -arch="${XC_ARCH}" \ -osarch="${XC_EXCLUDE_OSARCH}" \ -ldflags "${LD_FLAGS}" \ - -output "dist/${BUILD_PREFIX}{{.OS}}-{{.Arch}}" \ + -output "dist/${BUILD_PREFIX}-{{.OS}}-{{.Arch}}" \ . # Copy our OS/Arch to the bin/ directory # only when not running in CI DEV_PLATFORM="./dist/${BUILD_PREFIX}$(go env GOOS)-$(go env GOARCH)" if [[ -f "${DEV_PLATFORM}" && -z "${CI}" ]]; then + mkdir -p bin/ echo - echo "==> Moving ${DEV_PLATFORM} to bin/" + echo "==> Copy ${DEV_PLATFORM} to bin/" cp "${DEV_PLATFORM}" "./bin/${BIN_NAME}" fi # Packaging operations -# only if not a pull request -if [[ -z "${CI}" || "${TRAVIS_PULL_REQUEST}" == "false" ]]; then - echo - echo "==> Packaging..." - echo - for file in ./dist/*; do - echo "--> ${file}" - - echo " calculate hash..." - sha256sum "./${file}" >"./${file}.sha256" - done - - # Done! - echo - echo "==> Results:" - echo - ls -hl dist/* +if [[ -n "${CI}" ]]; then + echo + echo "==> Packaging..." + echo + for file in ./dist/*; do + echo "--> ${file}" + + echo " calculate hash..." + sha256sum "./${file}" >"./${file}.sha256" + + # IF there is a file extension, find and store it + if [[ ${file##*/} =~ \. ]]; then + ext="${file##*.}" + if [[ -n ${ext} ]]; then + ext=".${ext}" + fi + fi + + build="./dist/${BUILD_PREFIX}${ext}" + sha="./dist/${BUILD_PREFIX}${ext}.sha256" + + echo "build: ${build}" + echo "sha: ${sha}" + + mv -f "${file}" "${build}" + mv -f "${file}.sha256" "${sha}" + + if [[ -n $ext ]]; then + zip -j "${file%.*}" "${build}" "${sha}" + else + zip -j "${file}" "${build}" "${sha}" + fi + + rm -f "${build}" "${sha}" + done + + # Done! + echo + echo "==> Results:" + echo + ls -hl dist/* fi