This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
on tag #18
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: Build and Dockerize | |
on: | |
push: | |
tags: | |
- 'v*' | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Extract tag name | |
id: extract_tag | |
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
continue-on-error: true | |
with: | |
context: . | |
push: true | |
tags: ghcr.io/ark-network/clark:latest,ghcr.io/ark-network/clark:${{ env.TAG }} | |
platforms: linux/amd64,linux/arm64 | |
binary: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest] | |
arch: [amd64, arm64] | |
include: | |
- os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
- os: ubuntu-latest | |
target: aarch64-unknown-linux-gnu | |
- os: macos-latest | |
target: x86_64-apple-darwin | |
- os: macos-latest | |
target: aarch64-apple-darwin | |
steps: | |
- name: Extract tag name | |
id: extract_tag | |
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Install dependencies on Ubuntu | |
if: runner.os == 'Linux' | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y clang protobuf-compiler libssl-dev | |
if [ "${{ matrix.arch }}" == "arm64" ]; then | |
sudo apt-get install -y gcc-aarch64-linux-gnu protobuf-compiler libssl-dev:arm64 | |
export OPENSSL_DIR=/usr/aarch64-linux-gnu | |
fi | |
- name: Install dependencies on macOS | |
if: runner.os == 'macOS' | |
run: | | |
brew install protobuf openssl | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
toolchain: stable | |
override: true | |
components: rustfmt, clippy | |
- name: Install cross | |
run: cargo install cross | |
- name: Add Rust targets | |
run: rustup target add ${{ matrix.target }} | |
- name: Cross compile | |
run: cross build --release --target ${{ matrix.target }} | |
- name: Archive binaries | |
run: | | |
mkdir -p dist | |
cp target/${{ matrix.target }}/release/* dist/ | |
tar -czvf dist/${{ matrix.target }}.tar.gz -C dist . | |
upload-binary: | |
runs-on: ubuntu-latest | |
needs: binary | |
steps: | |
- name: Extract tag name | |
id: extract_tag | |
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ env.TAG }} | |
release_name: Release ${{ env.TAG }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Assets | |
run: | | |
for target in x86_64-unknown-linux-gnu x86_64-apple-darwin aarch64-unknown-linux-gnu aarch64-apple-darwin; do | |
path="dist/$target.tar.gz" | |
echo "Uploading $path" | |
curl \ | |
--header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
--header "Content-Type: application/gzip" \ | |
--data-binary @$path \ | |
--request POST \ | |
"${{ steps.create_release.outputs.upload_url }}?name=$(basename $path)" | |
done | |
- name: Update Release Description | |
uses: actions/github-script@v5 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
script: | | |
const { owner, repo } = context.repo | |
const releaseId = ${{ steps.create_release.outputs.id }} | |
const dockerImage = `ghcr.io/ark-network/clark` | |
const newBody = `Docker image available at \`${dockerImage}\`. You can pull it using \`docker pull ${dockerImage}\`.` | |
github.rest.repos.updateRelease({ | |
owner, | |
repo, | |
release_id: releaseId, | |
body: newBody | |
}) |