You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

189 lines
6.0 KiB

name: "Build release binary"
on:
release:
types: [created]
jobs:
build_binaries:
name: Build release binary
strategy:
matrix:
include:
- bin: taker
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
- bin: taker
target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
- bin: taker
target: x86_64-apple-darwin
os: macos-latest
archive_ext: tar
- bin: maker
target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
- bin: maker
target: aarch64-unknown-linux-gnu
os: ubuntu-latest
archive_ext: tar
- bin: maker
target: x86_64-apple-darwin
os: macos-latest
archive_ext: tar
runs-on: ${{ matrix.os }}
steps:
- name: Checkout tagged commit
uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.release.target_commitish }}
token: ${{ secrets.ITCHY_GITHUB_TOKEN }}
- name: Fetch all tags (workaround for https://github.com/actions/checkout/issues/290)
run: git fetch --tags --force
- name: Install toolchain from `rust-toolchain.toml`
run: rustup show
- uses: Swatinem/rust-cache@v1.3.0
with:
key: ${{ matrix.target }}
- name: Install compiler for aarch64 arch (armv8)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install 'gcc-aarch64-linux-gnu'
- uses: actions/setup-node@v2
with:
node-version: '16'
cache: yarn
cache-dependency-path: '**/yarn.lock'
- name: Build frontends
shell: bash
run: |
cd ${{ matrix.bin }}-frontend;
yarn
yarn build
- name: Build ${{ matrix.target }} ${{ matrix.bin }} release binary
run: cargo build --target=${{ matrix.target }} --release --bin ${{ matrix.bin }}
- name: Smoke test the binary
# aarch64-* is only cross-compiled, no smoke test
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: target/${{ matrix.target }}/release/${{ matrix.bin }} --help
# Remove once python 3 is the default
- uses: actions/setup-python@v2.3.1
with:
python-version: '3.x'
- id: create-archive-name
shell: python # Use python to have a prettier name for the archive.
run: |
import platform
os_info = platform.uname()
arch = os_info.machine
triple = "${{ matrix.target }}".split("-")
arch = triple[0]
archive_name=f'${{ matrix.bin }}_${{ github.event.release.tag_name }}_{os_info.system}_{arch}.${{ matrix.archive_ext }}'
print(f'::set-output name=archive::{archive_name}')
- name: Pack macos archive
if: matrix.os == 'macos-latest'
shell: bash
run: gtar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} ${{ matrix.bin }}
- name: Pack linux archive
if: matrix.os == 'ubuntu-latest'
shell: bash
run: tar -C ./target/${{ matrix.target }}/release --create --file=${{ steps.create-archive-name.outputs.archive }} ${{ matrix.bin }}
- name: Upload archive
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.ITCHY_GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./${{ steps.create-archive-name.outputs.archive }}
asset_name: ${{ steps.create-archive-name.outputs.archive }}
asset_content_type: application/gzip
build_docker_image:
needs: build_binaries
name: Build docker images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- bin: maker
- bin: taker
env:
GITHUB_TOKEN: ${{ secrets.ITCHY_GITHUB_TOKEN }}
steps:
- name: Checkout tagged commit
uses: actions/checkout@v2.4.0
with:
ref: ${{ github.event.release.target_commitish }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up docker buildx
uses: docker/setup-buildx-action@v1
- name: Login into github registry
uses: docker/login-action@v1.10.0
with:
registry: ghcr.io
username: ${{ github.repository }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Download release from github
run: |
gh release download ${{ github.event.release.tag_name }} -p '${{matrix.bin}}*Linux_x86_64*' -p '${{matrix.bin}}*aarch64*'
- name: Unpack archives
run: |
# We need to extract into sub folders to so that our dockerimage can fine the binaries.
#
# By providing `platform` to `docker buildx` the variable `TARGETPLATFORM` will be available
# when building the image. This variable is either
# `linux/amd64/`, `linux/arm64/`. Hence we need to extract into subfolders.
7z x ${{matrix.bin}}_${{ github.event.release.tag_name }}_Linux_aarch64.tar -olinux/arm64/
7z x ${{matrix.bin}}_${{ github.event.release.tag_name }}_Linux_x86_64.tar -olinux/amd64/
chmod a+x linux/amd64/*
chmod a+x linux/arm64/*
- name: Build docker image for ${{matrix.bin}}
run: |
VERSION=${{ github.event.release.tag_name }}
if [ "$VERSION" = "preview" ]; then
VERSION=latest
fi
docker buildx build \
--push \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source https://github.com/${{ github.repository }}" \
--tag ghcr.io/${{ github.repository }}/${{matrix.bin}}:${VERSION} \
--build-arg BINARY_PATH=${{matrix.bin}} \
.