From 53375b271f6f51aa7a1bbf8e5cd8fc2e800381f8 Mon Sep 17 00:00:00 2001 From: Greg Junge Date: Tue, 27 Jun 2023 09:51:53 -0500 Subject: [PATCH] Release/v2.3.5 (#155) * update github actions and makefile (#152) * Update release.yml --- .github/workflows/build.yml | 47 ----------------------- .github/workflows/docker.yml | 2 +- .github/workflows/gosec.yml | 16 +++++--- .github/workflows/lint.yml | 12 ++++-- .github/workflows/release.yml | 72 +++++++++++++++++++++++++++++++---- .github/workflows/test.yml | 25 +++++++----- Makefile | 20 +++++++++- 7 files changed, 117 insertions(+), 77 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 0e37fd02..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: [push, pull_request] -name: every commit -jobs: - - build: - runs-on: ubuntu-latest - name: build - steps: - - uses: actions/checkout@v3 - - name: Setup go - uses: actions/setup-go@v4 - with: - go-version: 1.20.0 - - run: go build ./... - - test: - runs-on: ubuntu-latest - name: test - steps: - - name: Install Go - uses: actions/setup-go@v4 - with: - go-version: 1.20.0 - - name: Checkout code - uses: actions/checkout@v3 - - name: Test - run: go test ./... - -# Use --check or --exit-code when available (Go 1.19?) -# https://github.com/golang/go/issues/27005 - tidy: - runs-on: ubuntu-latest - name: tidy - steps: - - uses: actions/checkout@v3 - - name: Setup go - uses: actions/setup-go@v4 - with: - go-version: 1.20.0 - - run: | - go mod tidy - CHANGES_IN_REPO=$(git status --porcelain) - if [[ -n "$CHANGES_IN_REPO" ]]; then - echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:" - git status && git --no-pager diff - exit 1 - fi diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bdd28129..076346df 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: docker-build +name: Docker Build on: pull_request: diff --git a/.github/workflows/gosec.yml b/.github/workflows/gosec.yml index d7be3dd6..770493a5 100644 --- a/.github/workflows/gosec.yml +++ b/.github/workflows/gosec.yml @@ -3,9 +3,11 @@ on: push: branches: - main + - release/* pull_request: branches: - main + - release/* jobs: tests: runs-on: ubuntu-latest @@ -14,14 +16,16 @@ jobs: steps: - name: Checkout Source uses: actions/checkout@v3 - - uses: technote-space/get-diff-action@v3 + + - uses: technote-space/get-diff-action@v6 with: - SUFFIX_FILTER: | - .go - .mod - .sum + PATTERNS: | + **.go + **.mod + **.sum + - name: Run Gosec Security Scanner uses: informalsystems/gosec@master with: args: ./... - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 77356670..e32cba60 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,33 +2,37 @@ name: Lint # Lint runs golangci-lint over the entire Gaia repository # This workflow is run on every pull request and push to main # The `golangci` job will pass without running if no *.{go, mod, sum} files have been modified. + on: pull_request: push: branches: - main - - master - "release/*" + jobs: golangci: name: golangci-lint runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 + - name: Setup Go uses: actions/setup-go@v4 with: go-version: 1.20.0 - - uses: actions/checkout@v3 - - uses: technote-space/get-diff-action@v4 + + - uses: technote-space/get-diff-action@v6 with: PATTERNS: | **/**.go go.mod go.sum + - uses: golangci/golangci-lint-action@v3 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. version: v1.51.2 args: --timeout 10m github-token: ${{ secrets.github_token }} - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6539814e..cc86d701 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,9 +13,10 @@ jobs: if: startsWith(github.ref, 'refs/tags/') runs-on: ubuntu-latest steps: - - name: Create release for ${{github.ref_name}} - run: gh release create ${{github.ref_name}} --prerelease --generate-notes --repo ${{github.repository}} + - name: Create release for ${{ github.ref_name }} + run: gh release create ${{ github.ref_name }} --prerelease --generate-notes --repo ${{ github.repository }} + artifacts: if: startsWith(github.ref, 'refs/tags/') needs: release @@ -25,17 +26,18 @@ jobs: strategy: matrix: build_type: ['build-release-arm64', 'build-release-amd64'] + # build_type: ['build/linux/amd64', 'build/linux/arm64', 'build/darwin/amd64', 'build/darwin/arm64', 'build/windows/amd64'] steps: - name: Checkout uses: actions/checkout@v3 - name: Set version tag - run: echo "VERSION=$(echo ${{github.ref_name}} | sed 's/^v//')" >> $GITHUB_ENV + run: echo "VERSION=$(echo ${{ github.ref_name }} | sed 's/^v//')" >> $GITHUB_ENV - name: Create build directory run: mkdir -p build/release - - name: Build ${{matrix.build_type}} - run: make ${{matrix.build_type}} + - name: Build ${{ matrix.build_type }} + run: make ${{ matrix.build_type }} - name: Upload the artifacts to release - run: gh release upload ${{github.ref_name}} ./build/release/* + run: gh release upload ${{ github.ref_name }} ./build/release/* calculate-checksums: needs: artifacts @@ -47,7 +49,7 @@ jobs: - name: Create build directory run: mkdir -p build/release - name: Download artifacts - run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}} + run: gh release download ${{ github.ref_name }} --pattern '*.tar.gz' --dir build/release --repo ${{ github.repository }} - name: Create checksums run: | cd build/release @@ -56,3 +58,59 @@ jobs: run: cat build/release/checksum.txt - name: Upload the checksum to release run: gh release upload ${{github.ref_name}} build/release/checksum.txt --repo ${{github.repository}} + + generate-json: + needs: calculate-checksums + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Install jq + run: sudo apt-get update && sudo apt-get install -y jq + - name: Create build directory + run: mkdir -p build/release + - name: Download artifacts + run: gh release download ${{github.ref_name}} --pattern '*.tar.gz' --dir build/release --repo ${{github.repository}} + - name: Generate JSON file + run: | + cd build/release + binaries=() + for file in *.tar.gz; do + checksum=$(sha256sum $file | awk '{print $1}') + url="https://github.com/${{github.repository}}/releases/download/${{github.ref_name}}/$file?checksum=sha256:$checksum" + declare -A TRANSLATION_MATRIX + TRANSLATION_MATRIX=( ["Linux_x86_64"]="linux/amd64" ["Linux_arm64"]="linux/arm64" ["Darwin_arm64"]="darwin/arm64" ) + os_architecture_translated="" + for key in "${!TRANSLATION_MATRIX[@]}"; do + if [[ "$file" == *"$key"* ]]; then + os_architecture_translated="${TRANSLATION_MATRIX[$key]}" + break + fi + done + if [ -z "$os_architecture_translated" ] + then + echo "Could not translate OS and architecture information from binary name: $file" + exit 1 + fi + binaries+=(" \"$os_architecture_translated\": \"$url\"") + done + binaries_json=$(IFS=$',\n'; echo "${binaries[*]}") + cat << EOF > binaries.json.raw + { + "binaries": { + $binaries_json + } + } + EOF + + - name: Pretty-print JSON file using jq + run: | + cd build/release + jq . < binaries.json.raw > binaries.json && rm binaries.json.raw + + - name: Display JSON file + run: cat build/release/binaries.json + - name: Upload the JSON file to release + run: gh release upload ${{ github.ref_name }} build/release/binaries.json --repo ${{ github.repository }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 37ff77a9..10508781 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,11 +1,11 @@ -name: Build & Test +name: Test + on: pull_request: - push: branches: - main - - master - - "release/*" + - release/* + jobs: cleanup-runs: runs-on: ubuntu-latest @@ -13,28 +13,32 @@ jobs: - uses: rokroskar/workflow-run-cleanup-action@master env: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'" test-coverage-upload: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - uses: actions/setup-go@v4 with: go-version: 1.20.0 - - uses: actions/checkout@v3 - - uses: technote-space/get-diff-action@v4 + + - uses: technote-space/get-diff-action@v6 + id: get-diff with: PATTERNS: | **/**.go go.mod go.sum + - name: build run: | make build + - name: test & coverage report creation run: | go test ./... -mod=readonly -timeout 12m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock' - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF + - name: filter out DONTCOVER run: | excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER')" @@ -44,12 +48,13 @@ jobs: echo "Excluding ${filename} from coverage report..." sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt done - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF + - uses: codecov/codecov-action@v1 with: file: ./coverage.txt # optional fail_ci_if_error: true - if: "env.GIT_DIFF != ''" + if: env.GIT_DIFF test-simulation: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index efdfa55d..3bb40f4c 100644 --- a/Makefile +++ b/Makefile @@ -119,6 +119,23 @@ else go build -mod=readonly $(BUILD_FLAGS) -o build/terrad ./cmd/terrad endif +build/linux/amd64: + GOOS=linux GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o "$@/terrad" ./cmd/terrad + +build/linux/arm64: + GOOS=linux GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) -o "$@/terrad" ./cmd/terrad + +build/darwin/amd64: + GOOS=darwin GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o "$@/terrad" ./cmd/terrad + +build/darwin/arm64: + GOOS=darwin GOARCH=arm64 go build -mod=readonly $(BUILD_FLAGS) -o "$@/terrad" ./cmd/terrad + +build/windows/amd64: + GOOS=windows GOARCH=amd64 go build -mod=readonly $(BUILD_FLAGS) -o "$@/terrad" ./cmd/terrad + +build-release: build/linux/amd64 build/linux/arm64 build/darwin/amd64 build/darwin/arm64 build/windows/amd64 + build-linux: mkdir -p $(BUILDDIR) docker build --no-cache --tag terramoney/core ./ @@ -134,8 +151,6 @@ build-linux-with-shared-library: docker cp temp:/lib/libwasmvm.so $(BUILDDIR)/ docker rm temp -build-release: build-release-amd64 build-release-arm64 - build-release-amd64: go.sum $(BUILDDIR)/ $(DOCKER) buildx create --name core-builder || true $(DOCKER) buildx use core-builder @@ -175,6 +190,7 @@ build-release-arm64: go.sum $(BUILDDIR)/ tar -czvf $(BUILDDIR)/release/terra_$(VERSION)_Linux_arm64.tar.gz -C $(BUILDDIR)/release/ terrad rm $(BUILDDIR)/release/terrad $(DOCKER) rm -f core-builder + install: go.sum go install -mod=readonly $(BUILD_FLAGS) ./cmd/terrad