Skip to content

v0.1.0

v0.1.0 #1

Workflow file for this run

name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g. v1.0.0)"
required: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
release-build:
name: Build Release Binary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Set up cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Build release binary
uses: actions-rs/cargo@v1
with:
command: build
args: --release
- name: Create release archive
run: |
mkdir -p ./release
cp target/release/l402-server-example-rs ./release/
cp README.md ./release/
cp LICENSE ./release/
cp docker-compose.yml ./release/
cp -r .env.example ./release/.env.example
cd release
tar czf ../l402-server-example-rs-linux-x64.tar.gz *
- name: Upload release assets
uses: actions/upload-artifact@v4
with:
name: release-binary
path: l402-server-example-rs-linux-x64.tar.gz
retention-days: 7
- name: Upload binary to release
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./l402-server-example-rs-linux-x64.tar.gz
asset_name: l402-server-example-rs-linux-x64.tar.gz
asset_content_type: application/gzip
docker-publish:
name: Push Docker image
runs-on: ubuntu-latest
needs: release-build
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set version tag
id: get_version
run: |
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${{ github.event.release.tag_name }}
else
VERSION=${{ github.event.inputs.tag }}
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest
type=raw,value=${{ env.VERSION }}
flavor: |
latest=true
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max