v0.3.30 #35
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
on: | |
workflow_dispatch: | |
inputs: | |
release: | |
type: string | |
required: false | |
description: 'e.g: v0.1.0' | |
build: | |
type: boolean | |
required: true | |
default: true | |
publish: | |
type: boolean | |
required: true | |
default: true | |
release: | |
types: | |
- published | |
permissions: | |
contents: write | |
name: Publish | |
env: | |
RELEASE: ${{ inputs.release || github.event.release.tag_name }} | |
jobs: | |
prepare-cargo: | |
if: ${{ github.event.release || inputs.build }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: cache cargo binaries | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
key: ${{ runner.os }}-cargo | |
- name: install cross binary | |
run: | | |
cargo install cross --git https://github.com/cross-rs/cross || true | |
publish-binaries: | |
if: ${{ github.event.release || inputs.build }} | |
needs: | |
- prepare-cargo | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- name: pse-linux-amd64 | |
target: x86_64-unknown-linux-musl | |
- name: pse-linux-arm64 | |
target: aarch64-unknown-linux-musl | |
- name: pse-linux-arm6 | |
target: arm-unknown-linux-musleabihf | |
- name: pse-linux-arm7 | |
target: armv7-unknown-linux-musleabihf | |
steps: | |
- name: use cached cargo binaries | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
key: ${{ runner.os }}-cargo | |
- uses: actions/checkout@v4 | |
- name: use cached dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-target-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: build | |
uses: actions-rs/cargo@v1 | |
with: | |
use-cross: true | |
command: build | |
args: --release --target ${{ matrix.target }} | |
- name: prepare binary | |
run: | | |
cp ./target/${{ matrix.target }}/release/pse ./${{ matrix.name }} | |
- name: verify binary | |
run: | | |
ls -l | |
- name: publish binary | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release upload ${{ env.RELEASE }} ./${{ matrix.name }} --clobber | |
publish-docker: | |
if: ${{ always() && (github.event.release || inputs.publish) }} | |
needs: | |
- publish-binaries | |
runs-on: ubuntu-latest | |
env: | |
REPO: ${{ github.repository }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: build args | |
id: build-args | |
run: | | |
VERSION=${RELEASE} | |
if [[ $VERSION =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then | |
MAJOR="${BASH_REMATCH[1]}" | |
MINOR="${BASH_REMATCH[2]}" | |
PATCH="${BASH_REMATCH[3]}" | |
TAGS="${REPO}:latest" | |
TAGS="${TAGS},${REPO}:${MAJOR}" | |
TAGS="${TAGS},${REPO}:${MAJOR}.${MINOR}" | |
TAGS="${TAGS},${REPO}:${MAJOR}.${MINOR}.${PATCH}" | |
else | |
echo "Bad version detected: ${VERSION}" | |
exit 1 | |
fi | |
echo "version=${VERSION}" >> $GITHUB_OUTPUT | |
echo "tags=${TAGS}" >> $GITHUB_OUTPUT | |
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT | |
- name: set up QEMU | |
uses: docker/[email protected] | |
- name: set up docker buildx | |
uses: docker/[email protected] | |
- name: login to docker hub | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKER_HUB_USERNAME }} | |
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} | |
- name: download published binaries | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release download ${{ env.RELEASE }} -D ./release | |
- name: build and push docker image | |
uses: docker/[email protected] | |
with: | |
context: . | |
file: ./Dockerfile.release | |
platforms: | | |
linux/amd64 | |
linux/arm64 | |
linux/arm/v6 | |
linux/arm/v7 | |
target: release | |
push: true | |
tags: ${{ steps.build-args.outputs.tags }} | |
labels: | | |
version=${{ steps.build-args.outputs.version }} | |
org.opencontainers.image.version=${{ steps.build-args.outputs.version }} | |
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | |
org.opencontainers.image.title=${{ github.event.repository.name }} | |
org.opencontainers.image.description=${{ github.event.repository.description }} | |
org.opencontainers.image.url=${{ github.event.repository.html_url }} | |
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} |