Skip to content

chore: config ci/cd (#8) #1

chore: config ci/cd (#8)

chore: config ci/cd (#8) #1

Workflow file for this run

name: Release
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
APP_NAME: atm0s-cloud-admin-panel
ARTIFACT_DIR: release-builds
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
SKIP_FRONTEND_BUILD: true
jobs:
build-release:
name: build-release
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: 1
strategy:
matrix:
build:
- linux gnu x64
- linux gnu aarch64
- macos x64
- macos aarch64
include:
- build: linux gnu x64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- build: linux gnu aarch64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- build: macos x64
os: macos-latest
target: x86_64-apple-darwin
- build: macos aarch64
os: macos-latest
target: aarch64-apple-darwin
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install deps
if: matrix.build == 'linux gnu x64'
run: |
sudo apt-get update
sudo apt install -y libssl-dev
- uses: actions/setup-node@v3
with:
node-version: 22
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Build admin-panel frontend
run: cd bin/admin-panel/view && pnpm install && pnpm build
- name: Build admin-panel binary
uses: houseabsolute/actions-rust-cross@v0
with:
target: ${{ matrix.target }}
args: "--locked --release --package ${{ env.APP_NAME }}"
strip: false
- name: Display structure of built files
run: ls -R target/
- name: Upload Artifact to Summary
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-${{ matrix.target }}
path: |
target/${{ matrix.target }}/release/${{ env.APP_NAME }}
- name: Upload server binary to release
if: startsWith(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/${{ matrix.target }}/release/${{ env.APP_NAME }}
asset_name: ${{ env.APP_NAME }}-${{ matrix.target }}
tag: ${{ github.ref }}
overwrite: true
create-release:
# only run if not a tags build
if: startsWith(github.ref, 'refs/tags/') == false
needs: build-release
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: create_release
id: create_release
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: ${{ github.event_name == 'workflow_dispatch' && 'latest' || (github.ref == 'refs/heads/main' && 'latest') || github.ref }}
title: Build ${{ github.event_name == 'workflow_dispatch' && 'development' || github.ref }}
files: |
*/*
prerelease: true
deploy-docker:
needs: build-release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/download-artifact@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}