fix: Update test #72
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 | |
on: | |
push: | |
branches: [main] | |
tags: [v*.*.*] | |
pull_request: | |
workflow_call: | |
inputs: | |
tag-name: | |
required: true | |
type: string | |
outputs: | |
image_tags: | |
value: ${{ jobs.docker.outputs.image_tags }} | |
image_url: | |
value: https://ghcr.io/${{ github.repository }} | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
if: ${{ !( github.workflow == 'build' && startsWith(github.event.head_commit.message, 'release:') && github.event.head_commit.author.name == 'github-actions[bot]' ) }} | |
permissions: | |
contents: write | |
strategy: | |
fail-fast: false | |
matrix: | |
target: [aarch64-unknown-linux-gnu, aarch64-unknown-linux-musl, x86_64-unknown-netbsd] | |
use-cross: [true] | |
include: | |
- target: x86_64-unknown-linux-gnu | |
use-cross: false | |
- target: x86_64-unknown-linux-musl | |
use-cross: false | |
- os: macos-12 | |
target: aarch64-apple-darwin | |
- os: macos-12 | |
target: x86_64-apple-darwin | |
- os: windows-2022 | |
target: x86_64-pc-windows-msvc | |
- os: windows-2022 | |
target: x86_64-pc-windows-gnu | |
runs-on: ${{ matrix.os || 'ubuntu-22.04'}} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
defaults: | |
run: | |
shell: bash -xe {0} | |
steps: | |
- name: Install musl tools | |
if: matrix.target == 'x86_64-unknown-linux-musl' | |
run: | | |
sudo apt-get install -y musl-tools --no-install-recommends | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: stable | |
target: ${{ matrix.target }} | |
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8 # v2.7.1 | |
with: | |
key: ${{ matrix.target }} | |
- name: Install cross | |
if: ${{ !matrix.os && matrix.use-cross }} | |
uses: taiki-e/install-action@6ee6c3ab83eab434138dfa928d72abc7eae14793 # v2.22.0 | |
with: | |
tool: cross | |
- run: ${{ (!matrix.os && matrix.use-cross) && 'cross' || 'cargo' }} build --locked --release --target ${{ matrix.target }} | |
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 | |
with: | |
name: ${{ matrix.target }} | |
path: | | |
target/${{ matrix.target }}/release/rust-ci-test | |
target/${{ matrix.target }}/release/rust-ci-test.exe | |
- name: Upload to release | |
if: ${{ inputs.tag-name }} | |
working-directory: target/${{ matrix.target }}/release/ | |
run: | | |
if [ -e rust-ci-test.exe ]; then | |
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}.exe" | |
mv rust-ci-test.exe "$filename" | |
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber | |
else | |
filename="rust-ci-test-${{ inputs.tag-name }}-${{ matrix.target }}" | |
mv rust-ci-test "$filename" | |
gh release upload ${{ inputs.tag-name }} "$filename"#${{ matrix.target }} --clobber | |
fi | |
docker: | |
needs: build | |
permissions: | |
packages: write | |
runs-on: 'ubuntu-22.04' | |
outputs: | |
image_tags: ${{ steps.meta.outputs.tags }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | |
with: | |
sparse-checkout: | | |
.github/workflows/build/Dockerfile | |
sparse-checkout-cone-mode: false | |
- name: Download build artifact | |
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 | |
with: | |
path: artifact | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 | |
- name: Log in to the Container registry | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@31cebacef4805868f9ce9a0cb03ee36c32df2ac4 # v5.3.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=semver,pattern={{version}},value=${{ inputs.tag-name }} | |
type=semver,pattern={{major}}.{{minor}},value=${{ inputs.tag-name }} | |
type=semver,pattern={{major}},value=${{ inputs.tag-name }} | |
type=edge | |
type=ref,event=branch | |
type=sha | |
- name: Build and push Docker image | |
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0 | |
with: | |
context: . | |
file: .github/workflows/build/Dockerfile | |
platforms: darwin/amd64,darwin/arm64,linux/amd64,linux/arm64,windows/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |