Skip to content

Commit

Permalink
Release/v2.4 (#138)
Browse files Browse the repository at this point in the history
* update makefile for go builder

* update build versions

* Feat/update release gh action (#134)

* generate binaries.json

* disable arm build while testing gh action

* generate binaries.json

---------

Co-authored-by: Michal Turcan <[email protected]>
Co-authored-by: Greg Junge <[email protected]>

* Update release.yml

---------

Co-authored-by: Michal Turcan <[email protected]>
Co-authored-by: Michal Turcan <[email protected]>
  • Loading branch information
3 people authored May 23, 2023
1 parent f513434 commit cc79659
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 9 deletions.
72 changes: 65 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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/checksum.txt --repo ${{ github.repository }}

20 changes: 18 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit cc79659

Please sign in to comment.