-
Notifications
You must be signed in to change notification settings - Fork 65
139 lines (122 loc) · 4.31 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
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