m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-08 05:03:49 -05:00

Optimize workflows (#25)

feat: optimize workflows

---------

Co-authored-by: Stavros <steveiliop56@gmail.com>
This commit is contained in:
Sergio
2024-09-06 21:46:43 +03:00
committed by GitHub
parent d67ffbf387
commit b5ebb33627
8 changed files with 171 additions and 101 deletions

47
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,47 @@
name: CI
on:
pull_request:
push:
branches: "main"
jobs:
build-binary:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Set up Bun
uses: oven-sh/setup-bun@v1
- name: Install deps
run: cd web && bun install
- name: Build
run: ./build.sh cargo build --verbose
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

View File

@@ -1,46 +1,48 @@
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
- name: Setup rust
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- 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: Set up Bun
uses: oven-sh/setup-bun@v1
- name: Upload CLI
- name: Install deps
run: cd web && bun install
- name: Build amd64 binary
run: |
./build.sh cross build --target x86_x64-unknown-linux-musl --release
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64
- name: Build arm64 binary
run: |
./build.sh cross build --target aarch64-unknown-linux-musl --release
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64
- 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
@@ -69,4 +71,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/*

View File

@@ -1,7 +1,6 @@
name: Release
on:
push:
tags: ["v*.*.*"]
workflow_dispatch:
jobs:
get-tag:
@@ -12,34 +11,50 @@ 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
uses: actions/checkout@v4
- name: Setup rust
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- 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: Upload binary
- name: Set up Bun
uses: oven-sh/setup-bun@v1
- name: Install deps
run: cd web && bun install
- name: Build amd64 binary
run: |
./build.sh cross build --target x86_x64-unknown-linux-musl --release
mv target/x86_x64-unknown-linux-musl/release/cup ./cup-linux-amd64
- name: Build arm64 binary
run: |
./build.sh cross build --target aarch64-unknown-linux-musl --release
mv target/aarch64-unknown-linux-musl/release/cup ./cup-linux-arm64
- 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
@@ -73,24 +88,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
@@ -100,6 +104,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/*

View File

@@ -1,20 +1,42 @@
FROM rust:alpine AS build
WORKDIR /
### Build UI ###
FROM node:20 AS web
# Install bun
RUN curl -fsSL https://bun.sh/install | bash
# Copy web folder
COPY ./web /web
WORKDIR /web
# Install requirements
RUN ~/.bun/bin/bun install
# Build frontend
RUN ~/.bun/bin/bun run build
### Build Cup ###
FROM rust:1.80.1-alpine AS build
# Requirements
RUN apk add musl-dev
RUN USER=root cargo new --bin cup
# Copy files
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 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
# Copy UI from web builder
COPY --from=web /web/dist src/static
# Build
RUN cargo build --release
### Main ###
FROM scratch
# Copy binary
COPY --from=build /cup/target/release/cup /cup
ENTRYPOINT ["/cup"]

View File

@@ -1,7 +1,16 @@
#!/bin/sh
rm -rf src/static
# This is kind of like a shim that makes sure the frontend is rebuilt when running a build. For example you can run `./build.sh cargo build --release`
# Frontend
cd web/
# Build
bun run build
# Copy UI to src folder
cp -r dist/ ../src/static
cargo build $@
# Run command from argv
$@

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.2.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 128 128" style="enable-background:new 0 0 128 128;" xml:space="preserve">
<path style="fill:#A6CFD6;" d="M65.12,17.55c-17.6-0.53-34.75,5.6-34.83,14.36c-0.04,5.2,1.37,18.6,3.62,48.68s2.25,33.58,3.5,34.95
c1.25,1.37,10.02,8.8,25.75,8.8s25.93-6.43,26.93-8.05c0.48-0.78,1.83-17.89,3.5-37.07c1.81-20.84,3.91-43.9,3.99-45.06
C97.82,30.66,94.2,18.43,65.12,17.55z"/>
<path style="fill:#DCEDF6;" d="M41.4,45.29c-0.12,0.62,1.23,24.16,2.32,27.94c1.99,6.92,9.29,7.38,10.23,4.16
c0.9-3.07-0.38-29.29-0.38-29.29s-3.66-0.3-6.43-0.84C44,46.63,41.4,45.29,41.4,45.29z"/>
<path style="fill:#6CA4AE;" d="M33.74,32.61c-0.26,8.83,20.02,12.28,30.19,12.22c13.56-0.09,29.48-4.29,29.8-11.7
S79.53,21.1,63.35,21.1C49.6,21.1,33.96,25.19,33.74,32.61z"/>
<path style="fill:#DC0D27;" d="M84.85,13.1c-0.58,0.64-9.67,30.75-9.67,30.75s2.01-0.33,4-0.79c2.63-0.61,3.76-1.06,3.76-1.06
s7.19-22.19,7.64-23.09c0.45-0.9,21.61-7.61,22.31-7.93c0.7-0.32,1.39-0.4,1.46-0.78c0.06-0.38-2.34-6.73-3.11-6.73
C110.47,3.47,86.08,11.74,84.85,13.1z"/>
<path style="fill:#8A1F0F;" d="M110.55,7.79c1.04,2.73,2.8,3.09,3.55,2.77c0.45-0.19,1.25-1.84,0.01-4.47
c-0.99-2.09-2.17-2.74-2.93-2.61C110.42,3.6,109.69,5.53,110.55,7.79z"/>
<g>
<path style="fill:#8A1F0F;" d="M91.94,18.34c-0.22,0-0.44-0.11-0.58-0.3l-3.99-5.77c-0.22-0.32-0.14-0.75,0.18-0.97
c0.32-0.22,0.76-0.14,0.97,0.18l3.99,5.77c0.22,0.32,0.14,0.75-0.18,0.97C92.21,18.3,92.07,18.34,91.94,18.34z"/>
</g>
<g>
<path style="fill:#8A1F0F;" d="M90.28,19.43c-0.18,0-0.35-0.07-0.49-0.2l-5.26-5.12c-0.28-0.27-0.28-0.71-0.01-0.99
c0.27-0.28,0.71-0.28,0.99-0.01l5.26,5.12c0.28,0.27,0.28,0.71,0.01,0.99C90.64,19.36,90.46,19.43,90.28,19.43z"/>
</g>
<g>
<path style="fill:#8A1F0F;" d="M89.35,21.22c-0.12,0-0.25-0.03-0.36-0.1l-5.6-3.39c-0.33-0.2-0.44-0.63-0.24-0.96
c0.2-0.33,0.63-0.44,0.96-0.24l5.6,3.39c0.33,0.2,0.44,0.63,0.24,0.96C89.82,21.1,89.59,21.22,89.35,21.22z"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.1 KiB