Skip to content

Commit

Permalink
refactor: try release action
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 17, 2024
1 parent 743077c commit 6760d6b
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 152 deletions.
85 changes: 0 additions & 85 deletions .github/workflows/nightly.yml

This file was deleted.

139 changes: 139 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: Release

on:
push:
branches:
- "main"
tags:
- "v*"
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
# https://github.com/Mozilla-Actions/sccache-action#rust-code
RUSTC_WRAPPER: "sccache"
SCCACHE_GHA_ENABLED: "true"

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
command: _build
musl: false
- target: x86_64-unknown-linux-musl
command: _build
musl: true
- target: aarch64-unknown-linux-gnu
command: _zigbuild
musl: false
- target: aarch64-unknown-linux-musl
command: _zigbuild
musl: true
name: build ${{ matrix.target }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: taiki-e/install-action@just
- uses: mozilla-actions/[email protected]
- if: matrix.command == '_zigbuild'
uses: korandoru/setup-zig@v1
with:
zig-version: master
- if: matrix.musl == true
run: sudo apt update && sudo apt install -y musl-tools && sudo ln -s /bin/g++ /bin/musl-g++
- run: just ${{ matrix.command }} ${{ matrix.target }}
- uses: actions/upload-artifact@v4
with:
name: hatsu.${{ matrix.target }}
path: target/${{ matrix.target }}/release/hatsu
if-no-files-found: error
retention-days: 30

docker:
name: docker buildx
runs-on: ubuntu-latest
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: hatsu.x86_64-unknown-linux-gnu
path: target_amd64
- uses: actions/download-artifact@v4
with:
name: hatsu.aarch64-unknown-linux-gnu
path: target_arm64
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
labels: |
org.opencontainers.image.title=Hatsu
org.opencontainers.image.description=Self-hosted & Fully-automated ActivityPub Bridge for Static Sites.
# https://github.com/docker/metadata-action#major-version-zero
tags: |
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v') }}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') }}
type=raw,value=beta,enable=${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref, 'beta') }}
type=raw,value=nightly,enable=${{ github.ref == 'refs/heads/main' }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

release:
if: startsWith(github.ref, 'refs/tags/v')
name: release
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- build
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: hatsu.x86_64-unknown-linux-gnu
path: target
- uses: actions/download-artifact@v4
with:
name: hatsu.aarch64-unknown-linux-gnu
path: target
- uses: actions/download-artifact@v4
with:
name: hatsu.x86_64-unknown-linux-musl
path: target
- uses: actions/download-artifact@v4
with:
name: hatsu.aarch64-unknown-linux-musl
path: target
- if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@v1
with:
draft: true
generate_release_notes: true
prerelease: ${{ contains(github.ref, 'beta') }}
files: |
target/hatsu.x86_64-unknown-linux-gnu
target/hatsu.aarch64-unknown-linux-gnu
target/hatsu.x86_64-unknown-linux-musl
target/hatsu.aarch64-unknown-linux-musl
59 changes: 10 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,18 @@
ARG PROFILE="release"
FROM bitnami/minideb:bookworm

########## CHEF ##########
FROM --platform=$BUILDPLATFORM rustlang/rust:nightly-bookworm-slim AS chef

RUN cargo install cargo-chef && \
# Install mold linker
apt update && apt install -y mold
ARG TARGETARCH

WORKDIR /app

########## PLANNER ##########
FROM chef AS planner

COPY . .

RUN cargo chef prepare --recipe-path recipe.json

########## BUILDER ##########
FROM chef AS builder

ARG PROFILE

RUN apt update && apt install -y openssl libssl-dev pkg-config

COPY --from=planner /app/recipe.json recipe.json

# cargo chef cook
RUN cargo chef cook \
$(if [ "$PROFILE" = "release" ]; then echo --release; fi) \
--recipe-path recipe.json
COPY target_${TARGETARCH}/hatsu /app/hatsu

COPY . .
RUN install_packages openssl libssl-dev ca-certificates curl && \
# https://github.com/casey/just#pre-built-binaries
curl -sSf https://just.systems/install.sh | bash -s -- --tag 1.23.0 --to /usr/local/bin && \
chmod +x /app/hatsu

# cargo build
RUN cargo build \
$(if [ "$PROFILE" = "release" ]; then echo --release; fi) \
&& mv ./target/$(if [ "$PROFILE" = "release" ]; then echo release; else echo debug; fi)/hatsu ./target/hatsu

########## RUNTIME ##########
FROM bitnami/minideb:bookworm AS runtime

WORKDIR /app

RUN apt update && \
apt install -y openssl libssl-dev pkg-config ca-certificates && \
# https://github.com/casey/just#pre-built-binaries
curl -sSf https://just.systems/install.sh | bash -s -- --tag 1.16.0 --to /usr/local/bin

# copy hatsu bin
COPY --from=builder /app/target/hatsu /app/
# copy justfile
COPY --from=planner /app/Justfile /app/Justfile
ENTRYPOINT [ "/app/hatsu" ]

EXPOSE 3939/tcp
EXPOSE 3939

ENTRYPOINT [ "/app/hatsu" ]
STOPSIGNAL SIGTERM
18 changes: 0 additions & 18 deletions Dockerfile.nightly

This file was deleted.

0 comments on commit 6760d6b

Please sign in to comment.