Skip to content

Commit

Permalink
[R4R] add pre-release and release jobs (#863) (#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored May 5, 2022
1 parent ab4822a commit 3c55b67
Show file tree
Hide file tree
Showing 9 changed files with 2,797 additions and 10 deletions.
40 changes: 40 additions & 0 deletions .github/generate_change_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
checksum() {
echo $(sha256sum $@ | awk '{print $1}')
}
change_log_file="./CHANGELOG.md"
version="## $@"
version_prefix="## "
start=0
CHANGE_LOG=""
while read line; do
if [[ $line == *"$version_prefix"* ]] && [ $start == 0 ]; then
start=1
continue
fi
if [[ $line == *"$version_prefix"* ]] && [ $start == 1 ]; then
break;
fi
if [ $start == 1 ]; then
CHANGE_LOG+="$line\n"
fi
done < ${change_log_file}
MAINNET_ZIP_SUM="$(checksum mainnet_config.zip)"
TESTNET_ZIP_SUM="$(checksum testnet_config.zip)"
LINUX_BIN_SUM="$(checksum linux_binary.zip)"
MAC_BIN_SUM="$(checksum macos_binary.zip)"
WINDOWS_BIN_SUM="$(checksum windows_binary.zip)"
OUTPUT=$(cat <<-END
## Changelog\n
${CHANGE_LOG}\n
## Assets\n
| Assets | Sha256 Checksum |\n
| :-----------: |------------|\n
| mainnet_config.zip | ${MAINNET_ZIP_SUM} |\n
| testnet_config.zip | ${TESTNET_ZIP_SUM} |\n
| linux_binary.zip | ${LINUX_BIN_SUM} |\n
| macos_binary.zip | ${MAC_BIN_SUM} |\n
| windows_binary.zip | ${WINDOWS_BIN_SUM} |\n
END
)
echo -e ${OUTPUT}
181 changes: 181 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
name: pre-release

on:
push:
# Publish `pre-v1.2.3` tags as releases.
tags:
- pre-v*

jobs:
build:
name: Build Release
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-18.04, macos-11, windows-2019]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Code
uses: actions/checkout@v2

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go env -w GOPRIVATE="github.com/bnb-chain/*"
- run: git config --global url."https://${{ secrets.GH_ACCESS_TOKEN }}@github.com".insteadOf "https://github.com"

# ==============================
# Linux/Macos/Windows Build
# ==============================

# used to debug workflow
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3

- name: Build Binary for ${{matrix.os}}
run: make build

# ==============================
# Upload artifacts
# ==============================

- name: Upload Linux Build
uses: actions/upload-artifact@v2
if: matrix.os == 'ubuntu-18.04'
with:
name: linux
path: ./build

- name: Upload MacOS Build
uses: actions/upload-artifact@v2
if: matrix.os == 'macos-11'
with:
name: macos
path: ./build

- name: Upload Windows Build
uses: actions/upload-artifact@v2
if: matrix.os == 'windows-2019'
with:
name: windows
path: ./build

release:
name: Release
needs: build
runs-on: ubuntu-18.04
steps:
- name: Checkout Code
uses: actions/checkout@v2

# ==============================
# Download artifacts
# ==============================

- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: linux
path: ./linux

- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: macos
path: ./macos

- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: windows
path: ./windows

- run: zip -r linux_binary.zip linux
- run: zip -r macos_binary.zip macos
- run: zip -r windows_binary.zip windows
- run: zip -r mainnet_config.zip asset/mainnet
- run: zip -r testnet_config.zip asset/testnet

- name: Create Release
id: create_release
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref_name }}
release_name: ${{ github.ref_name }}
body: |
git commit: ${{ github.sha }}
draft: true
prerelease: true

# Check downloaded files
- run: ls

- name: Upload Release Asset - Linux
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./linux_binary.zip
asset_name: linux_binary.zip
asset_content_type: application/octet-stream

- name: Upload Release Asset - MacOS
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./macos_binary.zip
asset_name: macos_binary.zip
asset_content_type: application/octet-stream

- name: Upload Release Asset - Windows
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./windows_binary.zip
asset_name: windows_binary.zip
asset_content_type: application/octet-stream

- name: Upload Mainnet Config
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./mainnet_config.zip
asset_name: mainnet_config.zip
asset_content_type: application/octet-stream

- name: Upload Testnet Config
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./testnet_config.zip
asset_name: testnet_config.zip
asset_content_type: application/octet-stream
54 changes: 44 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: release

on:
push:
Expand Down Expand Up @@ -108,9 +108,21 @@ jobs:
name: windows
path: ./windows

- run: zip -r linux.zip linux
- run: zip -r macos.zip macos
- run: zip -r windows.zip windows
- run: zip -r linux_binary.zip linux
- run: zip -r macos_binary.zip macos
- run: zip -r windows_binary.zip windows
- run: zip -r mainnet_config.zip asset/mainnet
- run: zip -r testnet_config.zip asset/testnet

- name: Generate Change Log
id: changelog
run: |
chmod 755 ./.github/generate_change_log.sh
CHANGELOG=$(./.github/generate_change_log.sh ${{ env.RELEASE_VERSION}})
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create Release
id: create_release
Expand All @@ -120,6 +132,8 @@ jobs:
with:
tag_name: ${{ github.ref_name }}
release_name: ${{ github.ref_name }}
body: |
${{ env.CHANGELOG }}
draft: false
prerelease: false

Expand All @@ -132,8 +146,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./linux.zip
asset_name: bnb-chain-node-binary-linux-${{ github.ref_name }}.zip
asset_path: ./linux_binary.zip
asset_name: linux_binary.zip
asset_content_type: application/octet-stream

- name: Upload Release Asset - MacOS
Expand All @@ -142,8 +156,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./macos.zip
asset_name: bnb-chain-node-binary-macos-${{ github.ref_name }}.zip
asset_path: ./macos_binary.zip
asset_name: macos_binary.zip
asset_content_type: application/octet-stream

- name: Upload Release Asset - Windows
Expand All @@ -152,6 +166,26 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./windows.zip
asset_name: bnb-chain-node-binary-windows-${{ github.ref_name }}.zip
asset_path: ./windows_binary.zip
asset_name: windows_binary.zip
asset_content_type: application/octet-stream

- name: Upload Mainnet Config
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./mainnet_config.zip
asset_name: mainnet_config.zip
asset_content_type: application/octet-stream

- name: Upload Testnet Config
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./testnet_config.zip
asset_name: testnet_config.zip
asset_content_type: application/octet-stream
Loading

0 comments on commit 3c55b67

Please sign in to comment.