Skip to content

Commit

Permalink
ci: add cross-rs build (#939)
Browse files Browse the repository at this point in the history
* ci: add cross-rs build

* add missing env

* add env file

* add build frontend

* use moonrepo setup toolchain

* use moon docker

* delete docker setup

* add artifact path

* download templates

* add path

* add path

* add ls

* add templates

* use abs

* typo

* rename artifact

* add build docker

* env permission

* add ghcr

* add libssl

* openssl

* remove curl

* add tar

* add path

* cd

* --strip-components

* cd

* apps/frontend/

* build frontend twice

* remove debug assertion

* build on host

* sudo

* arm64

* arm64

* libssl

* rustup

* ci: add new token

* set env

* Revert "build on host"

This reverts commit a47df4e.

* install libssl1.1 for arm64

* lint

* typo

* typo

* sh not bash

* y

* docker tag

* cache when not in a pull request

* delete old files

* enable

* passenv

* re-add the change from #944

* ci: change name of file

* ci: decide whether to run workflow in PR

* ci: test commit

Run CI.

* ci: test commit

Run CI.

* ci: Run CI

* ci: dump contents [Run CI]

* ci: add more logging [RUN CI]

* ci: select correct commit message [Run CI]

* ci: remove useless comment

* ci: add caching to docker action

* ci: test whole commit message if workflow should run

Run CI.

* also push to docker hub

* typo [Run CI]

* ci: enable dockerhub only for main releases

* ci: remove useless echo statements

[Run CI]

* use repository_owner [Run CI]

* ci: setup caching for building frontend

* ci: build only in release mode

[Run CI]

* ci: add new steps

* ci: change name of job

[Run CI]

* ci: change name of output

* ci: add step to create release

* ci: do not build frontend in gh action

* ci: do not build transactional in dockerfile

[Run CI]

* ci: change name of step

---------

Co-authored-by: Diptesh Choudhuri <[email protected]>
  • Loading branch information
vnghia and IgnisDa authored Aug 11, 2024
1 parent b1c1069 commit 161e0e7
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 233 deletions.
288 changes: 288 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
name: Main

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:
pre-workflow-checks:
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.check.outputs.should-run }}
should-release: ${{ steps.tag.outputs.should-release }}

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
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
COMMIT_MSG=$(git log --format=%B ${{ github.event.pull_request.head.sha }})
if [[ "$COMMIT_MSG" == *"Run CI"* ]]; then
echo "should-run=true" >> $GITHUB_OUTPUT
else
echo "should-run=false" >> $GITHUB_OUTPUT
fi
else
echo "should-run=false" >> $GITHUB_OUTPUT
fi
- name: Check tag
id: tag
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/tags/${{ github.ref_name }}" ]]; then
echo "should-release=true" >> $GITHUB_OUTPUT
else
echo "should-release=false" >> $GITHUB_OUTPUT
fi
create-release:
needs:
- pre-workflow-checks
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
uses: metcalfc/[email protected]
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
uses: softprops/action-gh-release@v1
with:
body: |
## What's Changed
${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build-transactional:
needs: pre-workflow-checks
if: needs.pre-workflow-checks.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: Set up Node.js and caching
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'yarn'
- name: Build emails
run: moon run transactional:build
- name: Upload templates artifact
uses: actions/upload-artifact@v4
with:
name: templates
path: |
apps/backend/templates/
retention-days: 1

build-backend:
needs:
- pre-workflow-checks
- build-transactional
if: needs.pre-workflow-checks.outputs.should-run == 'true'
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
platform:
- target: x86_64-unknown-linux-gnu
command: cargo
- target: aarch64-unknown-linux-gnu
command: cross

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"
- 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: |
${{ matrix.platform.command }} build --locked --target ${{ matrix.platform.target }} --release
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: backend-${{ steps.build.outputs.docker-arch }}
path: ${{ github.workspace }}/target/${{ matrix.platform.target }}/release/ryot
retention-days: 1

build-docker:
needs:
- pre-workflow-checks
- build-backend
if: needs.pre-workflow-checks.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.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to the docker hub container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
name=${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }},enable={{is_default_branch}}
name=${{ env.GHCR_REGISTRY }}/${{ github.repository_owner }}/${{ github.event.repository.name }}
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
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 }}

upload-kodi-plugin:
needs:
- pre-workflow-checks
- build-docker
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-20.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MOON_TOOLCHAIN_FORCE_GLOBALS: true

steps:
- uses: actions/checkout@v4
- name: Setup Moon
uses: moonrepo/setup-toolchain@v0
with:
auto-install: true
- name: Set up Node.js and caching
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'yarn'
- name: Build plugin
run: moon run kodi:build
- name: Upload plugin to releases
run: gh release upload --clobber ${{ github.ref_name }} "tmp/script.ryot.zip"

deploy-demo-instance:
needs:
- pre-workflow-checks
- build-docker
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up CLI
uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy
run: flyctl deploy --remote-only --detach --config ci/fly.toml
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

deploy-docs:
needs:
- pre-workflow-checks
- build-docker
if: needs.pre-workflow-checks.outputs.should-release == 'true'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install poetry
uses: abatilo/actions-poetry@v2
- name: Install dependencies
run: cd docs && poetry install
- name: Build docs
run: cd docs && poetry run mkdocs build
- name: Push to deployment branch
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: docs/site
publish_branch: nf-docs
force_orphan: true
Loading

0 comments on commit 161e0e7

Please sign in to comment.