diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml new file mode 100644 index 00000000..086e442d --- /dev/null +++ b/.github/workflows/build-pr.yml @@ -0,0 +1,52 @@ +name: Build PR (docker amd64) + +on: + pull_request: + branches: + - master + paths-ignore: + - "**.md" + - ".github/ISSUE_TEMPLATE/**" + +env: + PNPM_VERSION: 10 + NODE_VERSION: 20 + +jobs: + build-pr: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: ${{ env.PNPM_VERSION }} + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: pnpm + cache-dependency-path: "ui/pnpm-lock.yaml" + + - name: Install frontend dependencies & Build + working-directory: ui + run: | + pnpm install --production --prefer-offline --frozen-lockfile + pnpm run generate + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build commit to check (amd64 only) + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + push: false + cache-from: type=gha,scope=${{ github.workflow }} + cache-to: type=gha,mode=max,scope=${{ github.workflow }} + provenance: false + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 234c95b0..40c936f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,40 +1,22 @@ -name: build +name: Build Docker (native multi-arch) on: workflow_dispatch: inputs: - logLevel: - description: "Log level" - required: true - default: "warning" - type: choice - options: - - info - - warning - - debug build: - description: "Build" - required: false - default: false + description: "Build and publish native multi-arch image" type: boolean + default: true update_readme: - description: "Update Readme" - required: false - default: false + description: "Also sync DockerHub README" type: boolean - + default: false push: branches: - dev - master tags: - "v*" - paths-ignore: - - "**.md" - - ".github/**" - pull_request: - branches: - - "master" paths-ignore: - "**.md" - ".github/ISSUE_TEMPLATE/**" @@ -46,55 +28,21 @@ env: NODE_VERSION: 20 jobs: - build-pr: - runs-on: ubuntu-latest - if: github.event_name == 'pull_request' - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Install pnpm - uses: pnpm/action-setup@v4 - with: - version: ${{ env.PNPM_VERSION }} - - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: pnpm - cache-dependency-path: "ui/pnpm-lock.yaml" - - - name: Install frontend dependencies & Build - working-directory: ui - run: | - pnpm install --production --prefer-offline --frozen-lockfile - pnpm run generate - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build commit to check. - uses: docker/build-push-action@v5 - with: - context: . - platforms: linux/amd64 - push: false - cache-from: type=gha, scope=${{ github.workflow }} - cache-to: type=gha, mode=max, scope=${{ github.workflow }} - - push-build: - runs-on: ubuntu-latest - if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.build == 'true') + docker-build-arch: + name: Build image (${{ matrix.arch }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + arch: amd64 + - os: ubuntu-24.04-arm64 + arch: arm64 permissions: packages: write contents: write env: - PLATFORMS: ${{ startsWith(github.ref, 'refs/tags/v') && 'linux/amd64,linux/arm64' || 'linux/amd64' }} - + ARCH: ${{ matrix.arch }} steps: - name: Checkout uses: actions/checkout@v4 @@ -133,9 +81,7 @@ jobs: DATE=$(date -u +"%Y%m%d") BRANCH=$(echo "${GITHUB_REF#refs/heads/}" | sed 's/\//-/g') - echo "Current version: ${VERSION}, Branch: ${BRANCH}, SHA: ${SHA}, Date: ${DATE}" - - echo "APP_VERSION=${VERSION}" >> $"$GITHUB_ENV" + echo "APP_VERSION=${VERSION}" >> "$GITHUB_ENV" echo "APP_SHA=${SHA}" >> "$GITHUB_ENV" echo "APP_DATE=${DATE}" >> "$GITHUB_ENV" echo "APP_BRANCH=${BRANCH}" >> "$GITHUB_ENV" @@ -147,25 +93,20 @@ jobs: -e "s/^APP_BRANCH = \".*\"/APP_BRANCH = \"${BRANCH}\"/" \ app/library/version.py - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker meta + - name: Docker meta (arch-suffixed) id: meta uses: docker/metadata-action@v5 with: images: | ${{ env.DOCKERHUB_SLUG }} ${{ env.GHCR_SLUG }} - tags: | - type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} - type=ref,event=branch - type=ref,event=tag flavor: | latest=false + suffix=-${{ env.ARCH }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -180,16 +121,71 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push (native per-arch) uses: docker/build-push-action@v5 with: context: . - platforms: ${{ env.PLATFORMS }} + platforms: linux/${{ env.ARCH }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha, scope=${{ github.workflow }} - cache-to: type=gha, mode=max, scope=${{ github.workflow }} + cache-from: | + type=gha,scope=${{ github.workflow }} + type=registry,ref=ghcr.io/arabcoders/ytptube:buildcache + cache-to: | + type=gha,mode=max,scope=${{ github.workflow }} + type=registry,ref=ghcr.io/arabcoders/ytptube:buildcache,mode=max + provenance: false + + docker-publish-manifest: + name: Publish multi-arch manifest + needs: [docker-build-arch] + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Docker meta (final tags) + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ env.DOCKERHUB_SLUG }} + ${{ env.GHCR_SLUG }} + flavor: | + latest=false + tags: | + type=ref,event=branch + type=ref,event=tag + type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Create and push manifest list + shell: bash + run: | + IFS=$'\n' + for tag in $(echo "${{ steps.meta.outputs.tags }}"); do + echo "Creating manifest for ${tag}" + docker buildx imagetools create \ + --tag "$tag" \ + "${tag}-amd64" \ + "${tag}-arm64" + done - name: Overwrite GitHub release notes if: startsWith(github.ref, 'refs/tags/v') @@ -213,7 +209,7 @@ jobs: const { data: comparison } = await github.rest.repos.compareCommits({ owner: context.repo.owner, repo: context.repo.repo, - base: latestRelease.data[1]?.tag_name || '', // fallback to second latest tag + base: latestRelease.data[1]?.tag_name || '', head: tag, }); @@ -238,6 +234,7 @@ jobs: }); dockerhub-sync-readme: + name: DockerHub README sync runs-on: ubuntu-latest permissions: contents: read diff --git a/.vscode/settings.json b/.vscode/settings.json index f700e9c5..c80a6e10 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,6 +25,7 @@ "bilibili", "brainicism", "brotlicffi", + "buildcache", "choco", "consoletitle", "continuedl", @@ -52,10 +53,12 @@ "fribidi", "getpid", "gibibytes", + "gitpython", "gpac", "hiddenimports", "hookspath", "httpx", + "imagetools", "kibibytes", "levelno", "libcurl",