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

ci: add cross-rs build #939

Merged
merged 77 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
223a40f
ci: add cross-rs build
vnghia Aug 1, 2024
93d9ba3
add missing env
vnghia Aug 1, 2024
e79903d
add env file
vnghia Aug 1, 2024
d0a261c
add build frontend
vnghia Aug 1, 2024
57507d7
use moonrepo setup toolchain
vnghia Aug 1, 2024
623f802
use moon docker
vnghia Aug 1, 2024
61b493b
delete docker setup
vnghia Aug 2, 2024
962186c
add artifact path
vnghia Aug 2, 2024
d131576
download templates
vnghia Aug 2, 2024
b0a9f8e
add path
vnghia Aug 2, 2024
e5d2ded
add path
vnghia Aug 2, 2024
343ead8
add ls
vnghia Aug 2, 2024
e1827ed
add templates
vnghia Aug 2, 2024
b341a15
use abs
vnghia Aug 2, 2024
f786d56
typo
vnghia Aug 2, 2024
4c8b719
rename artifact
vnghia Aug 2, 2024
8ffe5d7
add build docker
vnghia Aug 2, 2024
f72a705
env permission
vnghia Aug 2, 2024
cc92427
add ghcr
vnghia Aug 2, 2024
af6376b
add libssl
vnghia Aug 2, 2024
27af5f1
openssl
vnghia Aug 2, 2024
fd956b6
remove curl
vnghia Aug 2, 2024
e30bd36
add tar
vnghia Aug 2, 2024
444af17
add path
vnghia Aug 2, 2024
3f2a1a0
cd
vnghia Aug 2, 2024
6218d41
--strip-components
vnghia Aug 2, 2024
a825e3f
cd
vnghia Aug 2, 2024
a11ef87
apps/frontend/
vnghia Aug 2, 2024
a5cc36d
build frontend twice
vnghia Aug 5, 2024
fe54d62
remove debug assertion
vnghia Aug 6, 2024
1ba0c96
build on host
vnghia Aug 6, 2024
cf9a6a9
sudo
vnghia Aug 6, 2024
5e5d480
arm64
vnghia Aug 6, 2024
8bab55c
arm64
vnghia Aug 6, 2024
ded239b
libssl
vnghia Aug 6, 2024
ecfc707
rustup
vnghia Aug 6, 2024
4846bfb
ci: add new token
IgnisDa Aug 7, 2024
65ff730
set env
vnghia Aug 7, 2024
bee3906
Revert "build on host"
vnghia Aug 7, 2024
7a0996a
install libssl1.1 for arm64
vnghia Aug 9, 2024
fcbbc88
lint
vnghia Aug 9, 2024
56aa50c
typo
vnghia Aug 9, 2024
30c0e24
typo
vnghia Aug 9, 2024
5d4b3a9
sh not bash
vnghia Aug 9, 2024
cc1cecf
y
vnghia Aug 9, 2024
7da3e93
docker tag
vnghia Aug 10, 2024
a92bbf1
cache when not in a pull request
vnghia Aug 10, 2024
41bde46
delete old files
vnghia Aug 10, 2024
ecce70e
enable
vnghia Aug 10, 2024
b2b26c7
passenv
vnghia Aug 10, 2024
fb9adc3
re-add the change from https://github.com/IgnisDa/ryot/pull/944
vnghia Aug 10, 2024
60c819b
ci: change name of file
IgnisDa Aug 10, 2024
c0eb6ea
Merge branch 'main' into ci
IgnisDa Aug 10, 2024
6481c79
ci: decide whether to run workflow in PR
IgnisDa Aug 10, 2024
14059ce
ci: test commit
IgnisDa Aug 10, 2024
56332e7
ci: test commit
IgnisDa Aug 10, 2024
c88ee15
ci: Run CI
IgnisDa Aug 10, 2024
847a261
ci: dump contents [Run CI]
IgnisDa Aug 10, 2024
e1ea0c2
ci: add more logging [RUN CI]
IgnisDa Aug 10, 2024
b2db804
ci: select correct commit message [Run CI]
IgnisDa Aug 10, 2024
d6af6a1
ci: remove useless comment
IgnisDa Aug 10, 2024
cd15292
ci: add caching to docker action
IgnisDa Aug 10, 2024
4c74ec5
ci: test whole commit message if workflow should run
IgnisDa Aug 10, 2024
c471fd5
also push to docker hub
vnghia Aug 10, 2024
226511f
typo [Run CI]
vnghia Aug 10, 2024
7ac5c6a
ci: enable dockerhub only for main releases
IgnisDa Aug 10, 2024
acfd102
ci: remove useless echo statements
IgnisDa Aug 10, 2024
4a6f237
use repository_owner [Run CI]
vnghia Aug 10, 2024
07ca7e5
ci: setup caching for building frontend
IgnisDa Aug 10, 2024
883eb0e
ci: build only in release mode
IgnisDa Aug 10, 2024
883f1fa
ci: add new steps
IgnisDa Aug 11, 2024
e931a4b
ci: change name of job
IgnisDa Aug 11, 2024
ebc8974
ci: change name of output
IgnisDa Aug 11, 2024
6d6055e
ci: add step to create release
IgnisDa Aug 11, 2024
a1a018b
ci: do not build frontend in gh action
IgnisDa Aug 11, 2024
6dc79e1
ci: do not build transactional in dockerfile
IgnisDa Aug 11, 2024
8c9bd19
ci: change name of step
IgnisDa Aug 11, 2024
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
191 changes: 191 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
name: Main
IgnisDa marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches: ["main"]
tags:
- "*-?v[0-9]+*"
pull_request:
branches: ["main"]
types: [opened, synchronize]

env:
GHCR_REGISTRY: ghcr.io

permissions:
contents: write
packages: write

jobs:
check-commit-message:
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.check.outputs.should-run }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check commit message
id: check
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
echo "should-run=true" >> $GITHUB_OUTPUT
echo "Event type is push, should-run is set to true"
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
COMMIT_MSG=$(git log --format=%B ${{ github.event.pull_request.head.sha }})
echo "Commit message: $COMMIT_MSG"
if [[ "$COMMIT_MSG" == *"Run CI"* ]]; then
echo "should-run=true" >> $GITHUB_OUTPUT
echo "Commit message contains 'Run CI', should-run is set to true"
else
echo "should-run=false" >> $GITHUB_OUTPUT
echo "Commit message does not contain 'Run CI', should-run is set to false"
fi
else
echo "should-run=false" >> $GITHUB_OUTPUT
echo "Event type is neither push nor pull_request, should-run is set to false"
fi
echo "Final should-run value: $(cat $GITHUB_OUTPUT | grep should-run | cut -d'=' -f2)"

build-frontend:
needs: check-commit-message
if: needs.check-commit-message.outputs.should-run == 'true'
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:
- check-commit-message
- build-frontend
if: needs.check-commit-message.outputs.should-run == 'true'

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.ref_type == 'tag' && 'release' || 'dev' }}" >> "$GITHUB_OUTPUT"
echo "output-dir=${{ github.event.ref_type == 'tag' && '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.event_name != 'pull_request' }}

- 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:
- check-commit-message
- build-backend
if: needs.check-commit-message.outputs.should-run == 'true'

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: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/${{ github.repository }}
tags: |
type=ref,event=pr
type=semver,pattern=v{{version}},enable={{is_default_branch}}
type=semver,pattern=v{{major}}.{{minor}},enable={{is_default_branch}}
type=semver,pattern=v{{major}},enable={{is_default_branch}}
type=raw,value=develop,enable={{is_default_branch}}

- name: Build and push to ghcr
uses: docker/build-push-action@v5
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
195 changes: 0 additions & 195 deletions .github/workflows/release.yml

This file was deleted.

10 changes: 10 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[build.env]
passthrough = [
"APP_VERSION",
"DEFAULT_TMDB_ACCESS_TOKEN",
"DEFAULT_MAL_CLIENT_ID",
"DEFAULT_GOOGLE_BOOKS_API_KEY",
]

[build]
pre-build = "ci/cross-pre-build.sh"
Loading
Loading