Merge pull request #190 from mindvalley/chore/download-to-specific-fo… #80
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
push: | |
tags: | |
- "[0-9]+.[0-9]+.[0-9]+*" | |
env: | |
CARGO_TERM_COLOR: always | |
CICD_INTERMEDIATES_DIR: "_cicd-intermediates" | |
WUKONG_HONEYCOMB_API_KEY: ${{ secrets.WUKONG_HONEYCOMB_API_KEY }} | |
jobs: | |
tag-name: | |
name: Get Version Name | |
runs-on: ubuntu-22.04 | |
outputs: | |
wukong_version: ${{ env.WUKONG_VERSION }} | |
steps: | |
- name: Get the release version from the tag | |
shell: bash | |
if: env.WUKONG_VERSION == '' | |
run: | | |
TAG_NAME=${{ github.ref }} | |
echo "WUKONG_VERSION=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV | |
echo "version is: ${{ env.WUKONG_VERSION }}" | |
build-release: | |
name: ${{ matrix.job.name }} (${{ matrix.job.target }}) | |
needs: [tag-name] | |
strategy: | |
fail-fast: false | |
matrix: | |
rust: [stable] | |
job: | |
- { | |
name: "macOS-arm", | |
target: aarch64-apple-darwin, | |
os: macos-latest, | |
} | |
- { name: "macOS-x86", target: x86_64-apple-darwin, os: macos-latest } | |
- { | |
name: "linux-x86", | |
target: x86_64-unknown-linux-gnu, | |
os: ubuntu-22.04, | |
use-cross: true, | |
} | |
- { | |
name: "linux-x86-musl", | |
target: x86_64-unknown-linux-musl, | |
os: ubuntu-22.04, | |
use-cross: true, | |
} | |
runs-on: ${{ matrix.job.os }} | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
submodules: "recursive" | |
- name: Setup Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
target: ${{ matrix.job.target }} | |
components: rustfmt, clippy | |
- name: Install protoc for Linux | |
if: contains(matrix.job.target, 'linux') | |
shell: bash | |
run: | | |
sudo apt -y update | |
sudo curl -sSLO https://github.com/protocolbuffers/protobuf/releases/download/v22.3/protoc-22.3-linux-x86_64.zip | |
sudo unzip protoc-22.3-linux-x86_64.zip -d /usr | |
which protoc | |
- name: Install protoc for macOS | |
if: contains(matrix.job.target, 'apple-darwin') | |
shell: bash | |
run: | | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
brew install protobuf | |
protoc --version | |
- name: Extract crate information | |
shell: bash | |
run: | | |
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' ./cli/Cargo.toml | head -n1)" >> $GITHUB_ENV | |
echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' ./cli/Cargo.toml | head -n1)" >> $GITHUB_ENV | |
echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' ./cli/Cargo.toml)" >> $GITHUB_ENV | |
echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' ./cli/Cargo.toml)" >> $GITHUB_ENV | |
- name: Build Wukong CLI | |
uses: actions-rs/cargo@v1 | |
with: | |
use-cross: ${{ matrix.job.use-cross }} | |
command: build | |
args: --locked --features prod --release --target=${{ matrix.job.target }} | |
- name: Create tarball | |
id: package | |
shell: bash | |
run: | | |
PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac; | |
PKG_BASENAME=${PROJECT_NAME}-v${{ needs.tag-name.outputs.wukong_version }}-${{ matrix.job.name }} | |
PKG_NAME=${PKG_BASENAME}${PKG_suffix} | |
echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT | |
BIN_NAME="${{ env.PROJECT_NAME }}" | |
echo "BIN_NAME=${BIN_NAME}" | |
echo "PKG_NAME=${PKG_NAME}" | |
PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" | |
ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" | |
mkdir -p "${ARCHIVE_DIR}" | |
mkdir -p "${ARCHIVE_DIR}/completions" | |
# Binary | |
cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "$ARCHIVE_DIR" | |
# Completions | |
cp -r ./cli/completions/{bash,fish,zsh} "$ARCHIVE_DIR/completions" | |
# base compressed package | |
pushd "${PKG_STAGING}/" >/dev/null | |
case ${{ matrix.job.target }} in | |
*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; | |
*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; | |
esac; | |
popd >/dev/null | |
# Let subsequent steps know where to find the compressed package | |
echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT | |
- name: "Artifact upload: tarball" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.package.outputs.PKG_NAME }} | |
path: ${{ steps.package.outputs.PKG_PATH }} | |
retention-days: 1 | |
publish: | |
needs: [build-release] | |
runs-on: ubuntu-22.04 | |
env: | |
GH_REPO: ${{ github.repository }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
permissions: | |
contents: write | |
pull-requests: write | |
steps: | |
# Must perform checkout first, since it deletes the target directory | |
# before running, and would therefore delete the downloaded artifacts | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: ./artifacts | |
- name: Display structure of downloaded files | |
run: ls -R ./artifacts | |
- name: Set TAG_NAME | |
run: | | |
TAG_NAME=${{ github.ref }} | |
echo "TAG_NAME=${TAG_NAME#refs/tags/}" >> $GITHUB_ENV | |
- run: echo 'PRERELEASE=' >> $GITHUB_ENV | |
- if: | | |
contains(env.TAG_NAME, 'dev') || | |
contains(env.TAG_NAME, 'alpha') || | |
contains(env.TAG_NAME, 'beta') || | |
contains(env.TAG_NAME, 'nightly') | |
run: | | |
echo 'PRERELEASE=--prerelease' >> $GITHUB_ENV | |
- name: Publish Github Release | |
env: | |
DEBUG: api | |
run: | | |
gh release create $TAG_NAME $PRERELEASE --title "$TAG_NAME" --target $GITHUB_SHA ./artifacts/*/*.tar.gz | |
- name: Calculate SHA256 Hash | |
id: sha256 | |
shell: bash | |
run: | | |
VERSION=${{ env.TAG_NAME }} | |
SHA256_MAC_ARM=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-arm.tar.gz/wukong-v${VERSION}-macOS-arm.tar.gz" | cut -f 1 -d " ") | |
SHA256_MAC_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-x86.tar.gz/wukong-v${VERSION}-macOS-x86.tar.gz" | cut -f 1 -d " ") | |
SHA256_LINUX_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-linux-x86.tar.gz/wukong-v${VERSION}-linux-x86.tar.gz"| cut -f 1 -d " ") | |
echo "${VERSION}" | |
echo "${SHA256_MAC_ARM}" | |
echo "${SHA256_MAC_X86}" | |
echo "${SHA256_LINUX_X86}" | |
echo "SHA256_MAC_ARM=${SHA256_MAC_ARM}" >> $GITHUB_OUTPUT | |
echo "SHA256_MAC_X86=${SHA256_MAC_X86}" >> $GITHUB_OUTPUT | |
echo "SHA256_LINUX_X86=${SHA256_LINUX_X86}" >> $GITHUB_OUTPUT | |
- uses: actions/checkout@v3 | |
with: | |
repository: mindvalley/homebrew-wukong | |
token: ${{ secrets.HOMEBREW_WUKONG_TOKEN }} | |
- name: Update Homebrew Formula | |
shell: bash | |
run: | | |
# remove original formula | |
rm ./wukong.rb | |
cp ./wukong.rb.template ./wukong.rb | |
# VERSION=${{ steps.sha256.outputs.VERSION }} | |
VERSION=${{ env.TAG_NAME }} | |
SHA256_MAC_ARM=${{ steps.sha256.outputs.SHA256_MAC_ARM }} | |
SHA256_MAC_X86=${{ steps.sha256.outputs.SHA256_MAC_X86 }} | |
SHA256_LINUX_X86=${{ steps.sha256.outputs.SHA256_LINUX_X86 }} | |
# SHA256_MAC_ARM=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-arm.tar.gz/wukong-v${VERSION}-macOS-arm.tar.gz" | cut -f 1 -d " ") | |
# SHA256_MAC_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-macOS-x86.tar.gz/wukong-v${VERSION}-macOS-x86.tar.gz" | cut -f 1 -d " ") | |
# SHA256_LINUX_X86=$(shasum -a 256 "./artifacts/wukong-v${VERSION}-linux-x86.tar.gz/wukong-v${VERSION}-linux-x86.tar.gz"| cut -f 1 -d " ") | |
echo "${VERSION}" | |
echo "${SHA256_MAC_ARM}" | |
echo "${SHA256_MAC_X86}" | |
echo "${SHA256_LINUX_X86}" | |
sed -i "s/__VERSION__/$VERSION/" ./wukong.rb | |
sed -i "s/__SHA256_MAC_ARM__/$SHA256_MAC_ARM/" ./wukong.rb | |
sed -i "s/__SHA256_MAC_X86__/$SHA256_MAC_X86/" ./wukong.rb | |
sed -i "s/__SHA256_LINUX_X86__/$SHA256_LINUX_X86/" ./wukong.rb | |
- name: Create a new PR to bump version | |
env: | |
DEBUG: api | |
run: | | |
VERSION=${{ env.TAG_NAME }} | |
NEW_BRANCH_NAME="release/${VERSION}" | |
git config --global user.email "[email protected]" | |
git config --global user.name "Gan Jun Kai" | |
git branch | |
git switch -c "${NEW_BRANCH_NAME}" | |
git add ./wukong.rb | |
git commit -m "release: bump version -> ${VERSION}" | |
git push origin "${NEW_BRANCH_NAME}" |