ci: migrate workflows and dependencies to Gitea Actions
This commit is contained in:
5 files changed
+166
-94
No files matched your search
@@ -17,3 +17,7 @@
|
||||
!build.sh
|
||||
!config.tsconfig.json
|
||||
!tsconfig.json
|
||||
|
||||
!.ci/
|
||||
!.ci/vendor/
|
||||
!.ci/vendor/yt-dlp
|
||||
@@ -0,0 +1,64 @@
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def lines(value):
|
||||
return [line.strip() for line in value.splitlines() if line.strip()]
|
||||
|
||||
|
||||
def output(name, value):
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as stream:
|
||||
stream.write(f'{name}<<GITEA_VALUE\n{value}\nGITEA_VALUE\n')
|
||||
|
||||
|
||||
def metadata(images, rules, sha):
|
||||
result = []
|
||||
for rule in lines(rules):
|
||||
fields = dict(part.split('=', 1) for part in rule.split(',') if '=' in part)
|
||||
if fields.get('enable', 'true').lower() == 'false':
|
||||
continue
|
||||
kind = fields.get('type')
|
||||
if kind == 'sha':
|
||||
tag = 'sha-' + sha[:7]
|
||||
elif kind == 'raw':
|
||||
tag = fields['value']
|
||||
else:
|
||||
raise ValueError('Unsupported metadata rule')
|
||||
if not re.fullmatch(r'[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}', tag):
|
||||
raise ValueError('Invalid image tag')
|
||||
result.extend(image.lower() + ':' + tag for image in lines(images))
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
mode = sys.argv[1]
|
||||
if mode == 'login':
|
||||
subprocess.run(['docker', 'login', os.environ['REGISTRY'], '--username', os.environ['REGISTRY_USER'], '--password-stdin'], input=os.environ['REGISTRY_TOKEN'], text=True, check=True)
|
||||
elif mode == 'metadata':
|
||||
output('tags', '\n'.join(metadata(os.environ['IMAGES'], os.environ['TAG_RULES'], os.environ['SOURCE_SHA'])))
|
||||
output('labels', 'org.opencontainers.image.revision=' + os.environ['SOURCE_SHA'])
|
||||
elif mode == 'build':
|
||||
command = ['docker', 'buildx', 'build', '--metadata-file', '/tmp/image-metadata.json']
|
||||
for env, flag in [('TAGS', '--tag'), ('LABELS', '--label'), ('BUILD_ARGS', '--build-arg')]:
|
||||
for value in lines(os.environ.get(env, '')):
|
||||
command.extend([flag, value])
|
||||
command += ['--label', 'org.opencontainers.image.revision=' + os.environ['SOURCE_SHA'], '--label', 'com.ermnvldmr.ci.run=' + os.environ['RUN_ID']]
|
||||
if os.environ.get('PLATFORMS'):
|
||||
command += ['--platform', os.environ['PLATFORMS']]
|
||||
if os.environ.get('DOCKERFILE'):
|
||||
command += ['--file', os.environ['DOCKERFILE']]
|
||||
if os.environ.get('PUSH', 'false').lower() == 'true':
|
||||
command.append('--push')
|
||||
command.append(os.environ.get('CONTEXT', '.'))
|
||||
subprocess.run(command, check=True)
|
||||
output('digest', json.loads(Path('/tmp/image-metadata.json').read_text())['containerimage.digest'])
|
||||
else:
|
||||
raise ValueError('Unknown docker operation')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,95 @@
|
||||
name: Continuous Integration
|
||||
'on':
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
mocha:
|
||||
runs-on: apex-debian13
|
||||
strategy:
|
||||
matrix:
|
||||
node-version:
|
||||
- 22.x
|
||||
pnpm-version:
|
||||
- 9
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
- run: |
|
||||
case "$PNPM_VERSION" in 8|9|9.12.3) ;; *) exit 1;; esac
|
||||
test -x "/opt/ci/pnpm/$PNPM_VERSION/bin/pnpm"
|
||||
echo "/opt/ci/pnpm/$PNPM_VERSION/bin" >> "$GITHUB_PATH"
|
||||
env:
|
||||
PNPM_VERSION: ${{ matrix.pnpm-version }}
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
run: |
|
||||
case "$NODE_VERSION" in
|
||||
18*) major=18;; 20*) major=20;; 22*) major=22;; *) exit 1;;
|
||||
esac
|
||||
test -x "/opt/ci/node/$major/bin/node"
|
||||
echo "/opt/ci/node/$major/bin" >> "$GITHUB_PATH"
|
||||
env:
|
||||
NODE_VERSION: ${{ matrix.node-version }}
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
- name: ESLint & Prettier
|
||||
run: pnpm run lint
|
||||
- name: Build
|
||||
run: pnpm run build
|
||||
- name: Test
|
||||
run: pnpm run --if-present test
|
||||
env:
|
||||
npm_config_build_from_source: 'true'
|
||||
docker:
|
||||
runs-on: apex-debian13
|
||||
needs: mocha
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v4
|
||||
- name: Stage verified yt-dlp asset
|
||||
run: |
|
||||
mkdir -p .ci/vendor
|
||||
cp /opt/ci/assets/yt-dlp .ci/vendor/yt-dlp
|
||||
- name: Set up QEMU
|
||||
run: test -r /proc/sys/fs/binfmt_misc/qemu-aarch64
|
||||
- name: Set up Docker Buildx
|
||||
run: |
|
||||
docker buildx version
|
||||
docker buildx create --name apex-ci --driver docker-container --use
|
||||
docker buildx inspect --bootstrap
|
||||
- name: Log in to Gitea Container Registry
|
||||
run: python3 .gitea/scripts/docker.py login
|
||||
env:
|
||||
REGISTRY: git.ermnvldmr.com
|
||||
REGISTRY_USER: ${{ github.repository_owner }}
|
||||
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||
- name: Docker Generate Meta
|
||||
id: meta
|
||||
run: python3 .gitea/scripts/docker.py metadata
|
||||
env:
|
||||
IMAGES: git.ermnvldmr.com/deytenit/quetza
|
||||
TAG_RULES: |
|
||||
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && !contains(github.ref_name, '-') }}
|
||||
type=raw,value=latest-dev,enable=${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
|
||||
type=raw,value=${{ github.ref_name }}
|
||||
type=raw,value=${{ github.sha }},enable=${{ github.ref_type == 'branch' }}
|
||||
SOURCE_SHA: ${{ github.sha }}
|
||||
- name: Build and Push Docker Image
|
||||
run: python3 .gitea/scripts/docker.py build
|
||||
env:
|
||||
TAGS: ${{ steps.meta.outputs.tags }}
|
||||
LABELS: ${{ steps.meta.outputs.labels }}
|
||||
BUILD_ARGS: ''
|
||||
DOCKERFILE: ''
|
||||
PLATFORMS: linux/amd64,linux/arm64
|
||||
PUSH: 'true'
|
||||
CONTEXT: .
|
||||
SOURCE_SHA: ${{ github.sha }}
|
||||
RUN_ID: ${{ github.run_id }}
|
||||
env:
|
||||
npm_config_build_from_source: 'true'
|
||||
@@ -1,92 +0,0 @@
|
||||
name: Continuous Integration
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
branches:
|
||||
- master
|
||||
|
||||
jobs:
|
||||
mocha:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [22.x]
|
||||
pnpm-version: [9]
|
||||
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: ${{ matrix.pnpm-version }}
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: ESLint & Prettier
|
||||
run: pnpm run lint
|
||||
|
||||
- name: Build
|
||||
run: pnpm run build
|
||||
|
||||
- name: Test
|
||||
run: pnpm run --if-present test
|
||||
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
needs: mocha
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Check out the repo
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- 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 GitHub Container Registry
|
||||
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker Generate Meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: |
|
||||
ghcr.io/deytenit/quetza
|
||||
# generate Docker tags based on the following events/attributes
|
||||
# on tag event: tag using git tag, and as latest if the tag doesn't contain hyphens (pre-releases)
|
||||
# on push event: tag using git sha, branch name and as latest-dev
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && !contains(github.ref_name, '-') }}
|
||||
type=raw,value=latest-dev,enable=${{ github.ref_type == 'branch' && github.ref_name == 'master' }}
|
||||
type=raw,value=${{ github.ref_name }}
|
||||
type=raw,value=${{ github.sha }},enable=${{ github.ref_type == 'branch' }}
|
||||
flavor: |
|
||||
latest=false
|
||||
|
||||
- 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 }}
|
||||
+3
-2
@@ -6,7 +6,8 @@ RUN apk add --no-cache make
|
||||
RUN apk add --no-cache gcc
|
||||
RUN apk add --no-cache build-base
|
||||
|
||||
RUN npm install -g pnpm
|
||||
RUN npm install -g pnpm@9.12.3
|
||||
ENV npm_config_build_from_source=true
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
@@ -19,7 +20,7 @@ COPY . .
|
||||
RUN pnpm run build
|
||||
|
||||
RUN mkdir ./dist/bin/
|
||||
RUN curl -L https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -o /usr/src/app/dist/bin/yt-dlp
|
||||
COPY .ci/vendor/yt-dlp /usr/src/app/dist/bin/yt-dlp
|
||||
RUN chmod a+rx /usr/src/app/dist/bin/yt-dlp
|
||||
|
||||
RUN pnpm install --prod
|
||||
|
||||
Reference in new issue
Block a user