Skip to content

fix: ci

fix: ci #8

Workflow file for this run

---
name: deploy
on:
workflow_dispatch: {}
release:
types: [published]
push:
branches:
- dev
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
VERSION: ${{ steps.prep.outputs.VERSION }}
VERSION_ADDON: ${{ steps.prep.outputs.VERSION_ADDON }}
VERSION_TS: ${{ steps.prep.outputs.VERSION_TS }}
VERSION_META: ${{ steps.prep.outputs.VERSION_META }}
REPO: ${{ steps.prep.outputs.REPO }}
steps:
- name: ⤵️ Checkout
uses: actions/[email protected]
- name: 🛠 Prepare envs
id: prep
working-directory: ./torrserver
run: |
VERSION=$(grep '^version: \w' config.yaml | sed 's/^.*: //')
VERSION_ADDON=$(echo $VERSION | cut -d "-" -f 1)
VERSION_TS=$(echo $VERSION | cut -d "-" -f 2)
VERSION_META=$(echo $VERSION | cut -d "-" -f 3)
REPO=${GITHUB_REPOSITORY}
echo "Version: ${VERSION}"
echo "Version ts: ${VERSION_TS}"
echo "Version meta: ${VERSION_META}"
echo "Repo: ${REPO}"
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
echo "VERSION_ADDON=${VERSION_ADDON}" >> "$GITHUB_OUTPUT"
echo "VERSION_TS=${VERSION_TS}" >> "$GITHUB_OUTPUT"
echo "VERSION_META=${VERSION_META}" >> "$GITHUB_OUTPUT"
echo "REPO=${REPO}" >> "$GITHUB_OUTPUT"
- name: 🏗 Prepare source
working-directory: ./torrserver/.build
run: |
rm -rf src
echo "Clone TorrServer-${{ steps.prep.outputs.VERSION_TS }}"
git clone --depth 1 --branch ${{ steps.prep.outputs.VERSION_TS }} https://github.com/YouROK/TorrServer.git src
echo "Set relative path for staticfiles"
jq -c '. + { "homepage": "./" }' ./src/web/package.json --indent 2 > ./src/web/package.$$.json
mv ./src/web/package.$$.json ./src/web/package.json
- name: 💾 Upload artifact
uses: actions/upload-artifact@v4
with:
name: src
path: ./torrserver/.build
if-no-files-found: error
include-hidden-files: true
deploy:
runs-on: ubuntu-latest
needs: prepare
strategy:
matrix:
architecture:
- amd64
- i386
- armhf
- armv7
- aarch64
steps:
- name: ⤵️ Checkout
uses: actions/[email protected]
- name: ℹ️ Compose build flags
id: flags
run: |
echo "date=$(date +"%Y-%m-%dT%H:%M:%SZ")" >> "$GITHUB_OUTPUT"
echo "from=${from}" >> "$GITHUB_OUTPUT"
if [[ "${{ matrix.architecture }}" = "amd64" ]]; then
echo "platform=linux/amd64" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "i386" ]]; then
echo "platform=linux/386" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armhf" ]]; then
echo "platform=linux/arm/v6" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "armv7" ]]; then
echo "platform=linux/arm/v7" >> "$GITHUB_OUTPUT"
elif [[ "${{ matrix.architecture }}" = "aarch64" ]]; then
echo "platform=linux/arm64" >> "$GITHUB_OUTPUT"
else
echo "::error ::Could not determine platform for architecture ${{ matrix.architecture }}"
exit 1
fi
- name: 🌏 Download artifact
uses: actions/download-artifact@v4
with:
name: src
path: ./torrserver/.build
- name: 📦 Set up build cache
id: cache
uses: actions/[email protected]
with:
path: /tmp/.docker-cache
key: docker-${{ matrix.architecture }}-${{ github.sha }}
restore-keys: |
docker-${{ matrix.architecture }}
- name: 📟 Set up QEMU
uses: docker/[email protected]
- name: 🚢 Set up Docker Buildx
uses: docker/[email protected]
- name: 🔑 Login to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🏗 Build
uses: docker/[email protected]
with:
load: true
context: ./torrserver/.build
cache-from: |
type=local,src=/tmp/.docker-cache
cache-to: type=local,mode=max,dest=/tmp/.docker-cache-new
platforms: ${{ steps.flags.outputs.platform }}
tags: |
ghcr.io/${{ needs.prepare.outputs.REPO }}/${{ matrix.architecture }}:${{ needs.prepare.outputs.VERSION }}
ghcr.io/${{ needs.prepare.outputs.REPO }}/${{ matrix.architecture }}:latest
build-args: |
BUILD_ARCH=${{ matrix.architecture }}
# This ugly bit is necessary, or our cache will grow forever...
# Well until we hit GitHub's limit of 5GB :)
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: 🚚 Swap build cache
run: |
rm -rf /tmp/.docker-cache
mv /tmp/.docker-cache-new /tmp/.docker-cache
docker images
- name: 🚀 Push
# yamllint disable rule:line-length
run: |
docker push "ghcr.io/${{ needs.prepare.outputs.REPO }}/${{ matrix.architecture }}:${{ needs.prepare.outputs.VERSION }}"
docker push "ghcr.io/${{ needs.prepare.outputs.REPO }}/${{ matrix.architecture }}:latest"