Skip to content

ci for server and web #28

ci for server and web

ci for server and web #28

name: ci for server and web
on:
push:
paths:
- "gogo-server/**"
- "gogo-web/**"
- ".github/workflows/ci_server_and_web.yml"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
ALPINE_RUST_TARGET: x86_64-unknown-linux-musl
jobs:
build-web:
if: ${{!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Npm
uses: actions/setup-node@v4
with:
node-version: 20
- name: Npm Build
working-directory: ./gogo-web
run: |
npm install
npm run build --omit=dev
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: gogo-web
path: ./gogo-web/dist/
retention-days: 1
build-server:
needs: [build-web]
runs-on: ${{ matrix.os }}
if: ${{!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')}}
strategy:
fail-fast: false
matrix:
include:
- build_name: linux-x86_64
os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
- build_name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
- build_name: macos-x86_64
os: macos-14
target: x86_64-apple-darwin
- build_name: macos-aarch64
os: macos-14
target: aarch64-apple-darwin
env:
PACKAGE_FILE: gogo-server-web-${{ matrix.target }}.${{ startsWith(matrix.build_name, 'win') && 'zip' || 'tar.gz' }}
CARGO_BUILD_DIR: ./gogo-server/target/${{ matrix.target }}/release
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Cargo build
working-directory: ./gogo-server
run: cargo build --release ${{ matrix.target && '--target' }} ${{ matrix.target }}
- name: Package common
run: |
mkdir package
cp ./gogo-server/config.json package/
- name: Download web package
uses: actions/download-artifact@v4
with:
name: gogo-web
path: package/
- name: Package Windows
if: runner.os == 'Windows'
run: |
dir ./gogo-server/target/${{ matrix.target }}/
cp ${{ env.CARGO_BUILD_DIR }}/gogo-server.exe package/
7z a ${{ env.PACKAGE_FILE }} ./package/*
- name: Package Linux or macOS
if: runner.os == 'Linux' || runner.os == 'macOS'
run: |
ls -lh ./gogo-server/target/${{ matrix.target }}/
cp ${{ env.CARGO_BUILD_DIR }}/gogo-server package/
cd package
tar -czvf ../${{ env.PACKAGE_FILE }} *
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: server-web-${{ matrix.target }}
# path: ${{ env.PACKAGE_FILE }}
path: package/
retention-days: 7
# - name: Upload package
# if: runner.os != 'macOS'
# run: gh release upload "${{ needs.create-nightly-release.outputs.tag_name }}" "${{ env.PACKAGE_FILE }}"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-server-for-alpine:
needs: [build-web]
if: ${{!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[skip ci]')}}
runs-on: ubuntu-latest
container:
image: rust:alpine
volumes:
- ./gogo-server:/gogo-server
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Install Rust toolchain
run: apk add --no-cache musl-dev openssl-dev
- name: Cargo build
run: |
ls -lh
cd gogo-server
cargo build --release --target ${{ env.ALPINE_RUST_TARGET }}
- name: Package
run: |
ls -lh
mkdir package
cp ./gogo-server/config.json package/
cp ./gogo-server/target/x86_64-unknown-linux-musl/release/gogo-server package/
- name: Download web package
uses: actions/download-artifact@v4
with:
name: gogo-web
path: package/
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: server-web-${{ env.ALPINE_RUST_TARGET }}
path: package/
retention-days: 7
build-docker:
needs: [build-server-for-alpine]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Clone repo
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Download web package
uses: actions/download-artifact@v4
with:
name: server-web-${{ env.ALPINE_RUST_TARGET }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile_workflow
push: true
tags: ${{ github.actor }}/${{ github.repository }}:latest
labels: ${{ steps.meta.outputs.labels }}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true