ci: add cross-rs build #19
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Main | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
workflow_dispatch: | |
env: | |
GHCR_REGISTRY: ghcr.io | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
build-frontend: | |
runs-on: ubuntu-latest | |
env: | |
MOON_TOOLCHAIN_FORCE_GLOBALS: true | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: moonrepo/setup-toolchain@v0 | |
with: | |
auto-install: true | |
- name: Build frontend | |
run: | | |
moon run frontend:build transactional:build | |
- name: Upload templates artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: templates | |
path: | | |
apps/backend/templates/ | |
retention-days: 1 | |
build-backend: | |
needs: | |
- build-frontend | |
strategy: | |
fail-fast: false | |
matrix: | |
platform: | |
- target: x86_64-unknown-linux-gnu | |
command: cargo | |
- target: aarch64-unknown-linux-gnu | |
command: cross | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: templates | |
path: ${{ github.workspace }}/apps/backend/templates/ | |
- name: Extract build information | |
id: build | |
env: | |
TARGET: ${{ matrix.platform.target }} | |
run: | | |
echo "version=${GITHUB_REF##*/}" >> "$GITHUB_OUTPUT" | |
echo "docker-arch=${{ startsWith(matrix.platform.target, 'x86_64') && 'amd64' || 'arm64' }}" >> "$GITHUB_OUTPUT" | |
echo "profile=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'dev' }}" >> "$GITHUB_OUTPUT" | |
echo "output-dir=${{ (github.event_name == 'release' || github.event_name == 'workflow_dispatch') && 'release' || 'debug' }}" >> "$GITHUB_OUTPUT" | |
- name: Extract rust toolchain | |
id: toolchain | |
run: | | |
echo "channel=$(grep channel rust-toolchain.toml | awk -F' = ' '{printf $2}' | tr -d '\"')" >> "$GITHUB_OUTPUT" | |
- uses: dtolnay/rust-toolchain@master | |
with: | |
toolchain: ${{ steps.toolchain.outputs.channel }} | |
targets: ${{ matrix.platform.target }} | |
- uses: Swatinem/rust-cache@v2 | |
with: | |
key: ${{ matrix.platform.target }}-${{ steps.build.outputs.profile }} | |
save-if: ${{ github.ref == 'refs/heads/main' }} | |
- name: Install cross | |
if: ${{ matrix.platform.command == 'cross' }} | |
uses: taiki-e/cache-cargo-install-action@v2 | |
with: | |
tool: cross | |
git: https://github.com/cross-rs/cross | |
rev: 19be83481fd3e50ea103d800d72e0f8eddb1c90c | |
locked: false | |
- name: Build | |
env: | |
APP_VERSION: ${{ steps.build.outputs.version }} | |
DEFAULT_TMDB_ACCESS_TOKEN: ${{ secrets.DEFAULT_TMDB_ACCESS_TOKEN }} | |
DEFAULT_MAL_CLIENT_ID: ${{ secrets.DEFAULT_MAL_CLIENT_ID }} | |
DEFAULT_GOOGLE_BOOKS_API_KEY: ${{ secrets.DEFAULT_GOOGLE_BOOKS_API_KEY }} | |
run: | | |
touch .env | |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --profile ${{ steps.build.outputs.profile }} | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-${{ steps.build.outputs.docker-arch }} | |
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/${{ steps.build.outputs.output-dir }}/ryot | |
retention-days: 1 | |
build-docker: | |
needs: | |
- build-backend | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download build artifact for docker | |
uses: actions/download-artifact@v4 | |
with: | |
path: ${{ github.workspace }}/artifact/ | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to the ghcr container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.GHCR_REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push to ghcr | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: Dockerfile.new | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ghcr.io/vnghia/ryot:test |