Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize workflows #24

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
pull_request:
push:
branches: "main"

jobs:
build-binary:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup rust
uses: actions-rust-lang/setup-rust-toolchain@v1

- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build
run: ./build.sh cargo-dev

build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: false
cache-from: type=gha
cache-to: type=gha,mode=max
67 changes: 40 additions & 27 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
name: Nightly Release
on:
push:
branches: main
workflow_dispatch:

jobs:
build-binary:
strategy:
matrix:
platform:
- release_for: linux-aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-musl
bin: cup
name: cup-linux-aarch64
command: build

- release_for: linux-x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: cup
name: cup-linux-x86_64
command: build

runs-on: ${{ matrix.platform.os }}
build-binaries:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,14 +15,28 @@ jobs:
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Build binary
run: cross ${{ matrix.platform.command }} --target ${{ matrix.platform.target }}
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build amd64 binary
run: |
./build.sh cross x86_x64-unknown-linux-musl
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64

- name: Build arm64 binary
run: |
./build.sh cross aarch64-unknown-linux-musl
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64

- name: Upload CLI
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.name }}
path: target/${{ matrix.platform.target }}/debug/${{ matrix.platform.bin }}
name: binaries
path: |
cup-linux-amd64
cup-linux-arm64

build-image:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -69,4 +65,21 @@ jobs:
push: true
tags: ghcr.io/sergi0g/cup:nightly
cache-from: type=gha
cache-to: type=gha,mode=max
cache-to: type=gha,mode=max

nightly-release:
runs-on: ubuntu-latest
needs: build-binaries
steps:
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
path: binaries

- uses: pyTooling/Actions/releaser@r0
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: nightly
rm: true
files: binaries/*
60 changes: 28 additions & 32 deletions .github/workflows/build.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Release
on:
push:
tags: ["v*.*.*"]
workflow_dispatch:

jobs:
get-tag:
Expand All @@ -12,15 +11,11 @@ jobs:
- name: Get current tag
id: tag
run: |
TAG=$(echo "$GITHUB_REF" | sed 's/^refs\/tags\///')
TAG=v$(head -n 4 Cargo.toml | grep version | awk '{print $3}' | tr -d '"')
echo "Current tag: $TAG"
echo "tag=$TAG" >> $GITHUB_OUTPUT
build-binary:
strategy:
matrix:
arch:
- aarch64
- x86_64

build-binaries:
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -32,14 +27,28 @@ jobs:
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross

- name: Build binary
run: cross build --target ${{ matrix.arch }}-unknown-linux-musl --release
- name: Set up node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Build amd64 binary
run: |
./build.sh cross x86_x64-unknown-linux-musl
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64

- name: Build arm64 binary
run: |
./build.sh cross aarch64-unknown-linux-musl
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64

- name: Upload binary
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: cup-linux-${{ matrix.arch }}
path: target/${{ matrix.arch }}-unknown-linux-musl/release/cup
name: binaries
path: |
cup-linux-amd64
cup-linux-arm64

build-image:
needs: get-tag
Expand Down Expand Up @@ -73,24 +82,13 @@ jobs:

release:
runs-on: ubuntu-latest
needs: [get-tag, build-image, build-binary]
needs: [get-tag, build-image, build-binaries]
steps:
- name: Download arm64 binary
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: cup-linux-aarch64
path: cup-linux-aarch64

- name: Download x86 binary
uses: actions/download-artifact@v4
with:
name: cup-linux-x86_64
path: cup-linux-x86_64

# - name: Extract and rename binaries
# run: |
# unzip /home/runner/work/cup/cup/cup-linux-aarch64 && mv /home/runner/work/cup/cup/cup cup-linux-aarch64
# unzip /home/runner/work/cup/cup/cup-linux-x86_64 && mv /home/runner/work/cup/cup/cup cup-linux-x86_64
name: binaries
path: binaries

- name: Create release
uses: softprops/action-gh-release@v2
Expand All @@ -100,6 +98,4 @@ jobs:
prerelease: true
tag_name: ${{ needs.get-tag.outputs.tag }}
name: ${{ needs.get-tag.outputs.tag }}
files: |
cup-linux-aarch64
cup-linux-x86_64
files: binaries/*
37 changes: 28 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
FROM rust:alpine AS build
WORKDIR /
# Build UI
FROM node:20-alpine3.20 as web

Check warning on line 2 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Copy web folder
COPY ./web ./web
WORKDIR web

Check warning on line 6 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-image

Relative workdir without an absolute workdir declared within the build can have unexpected results if the base image changes

WorkdirRelativePath: Relative workdir "web" can have unexpected results if the base image changes More info: https://docs.docker.com/go/dockerfile/rule/workdir-relative-path/

# Install requirements
RUN npm i

# Build
RUN npm run build

# Build Cup
FROM rust:1.80.1-alpine3.20 AS build

# Requirements
RUN apk add musl-dev

RUN USER=root cargo new --bin cup
# Copy rust
WORKDIR /cup

COPY Cargo.toml Cargo.lock .
RUN cargo build --release
RUN rm -rf src/
COPY Cargo.toml .
COPY Cargo.lock .
COPY ./src ./src

# Copy UI from web builder
COPY --from=web /web/dist src/static

COPY src src
# This is a very bad workaround, but cargo only triggers a rebuild this way for some reason
RUN printf "\n" >> src/main.rs
# Build
RUN cargo build --release

# Runner
FROM scratch

# Copy binary
COPY --from=build /cup/target/release/cup /cup

ENTRYPOINT ["/cup"]
33 changes: 29 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
#!/bin/sh
#!/bin/bash

rm -rf src/static
# Arguments
METHOD=$1
TARGET=$2

# Frontend
cd web/
bun run build

# Install requirements
npm i

# Build
npm run build

# Copy UI to src folder
cp -r dist/ ../src/static
cargo build $@

# Check selected method and build

if [[ $METHOD == 'cargo' ]]; then
echo "Building with cargo..."
cargo build --release
elif [[ $METHOD == 'cargo-dev' ]]; then
echo "Building with cargo using --verbose (dev)..."
elif [[ $METHOD == 'cross' ]]; then
echo "Building with cross for $TARGET..."
cross build --target $TARGET --release
else
echo "Unkown method!"
exit 1
fi
Binary file removed src/static/apple-touch-icon.png
Binary file not shown.
Binary file removed src/static/favicon.ico
Binary file not shown.
29 changes: 0 additions & 29 deletions src/static/favicon.svg

This file was deleted.