mirror of
https://github.com/elmerfds/TrafegoDNS.git
synced 2026-01-15 23:59:44 -06:00
120 lines
3.8 KiB
YAML
120 lines
3.8 KiB
YAML
name: PR Test Build
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
pr_number:
|
|
description: 'PR number to test'
|
|
required: true
|
|
type: string
|
|
platform:
|
|
description: 'Platform architecture to build'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- linux/amd64
|
|
- linux/arm64
|
|
- linux/arm/v7
|
|
- all
|
|
default: 'linux/amd64'
|
|
|
|
jobs:
|
|
build-pr-image:
|
|
name: Build PR Test Image
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
steps:
|
|
- name: Checkout PR
|
|
uses: actions/checkout@v4
|
|
with:
|
|
ref: refs/pull/${{ github.event.inputs.pr_number }}/head
|
|
fetch-depth: 0 # Fetch all history for all tags and branches
|
|
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Generate version info
|
|
id: version
|
|
run: |
|
|
# Get the version from package.json
|
|
PACKAGE_VERSION=$(node -p "require('./package.json').version")
|
|
|
|
# Generate date-based tag
|
|
DATE_TAG=$(date +'%Y%m%d')
|
|
|
|
# Get commit count for additional uniqueness
|
|
COMMIT_COUNT=$(git rev-list --count HEAD)
|
|
|
|
echo "PACKAGE_VERSION=${PACKAGE_VERSION}" >> $GITHUB_OUTPUT
|
|
echo "DATE_TAG=${DATE_TAG}" >> $GITHUB_OUTPUT
|
|
echo "COMMIT_COUNT=${COMMIT_COUNT}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Log in to GitHub Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Extract metadata for Docker
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: |
|
|
${{ secrets.DOCKER_USERNAME }}/trafegodns
|
|
ghcr.io/${{ github.repository }}
|
|
tags: |
|
|
# PR tag
|
|
type=raw,value=pr-${{ github.event.inputs.pr_number }}
|
|
|
|
# PR tag with date
|
|
type=raw,value=pr-${{ github.event.inputs.pr_number }}-${{ steps.version.outputs.DATE_TAG }}
|
|
|
|
# Determine platforms to build
|
|
- name: Set platforms
|
|
id: platforms
|
|
run: |
|
|
if [ "${{ github.event.inputs.platform }}" == "all" ]; then
|
|
echo "PLATFORMS=linux/amd64,linux/arm64,linux/arm/v7" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "PLATFORMS=${{ github.event.inputs.platform }}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
# Build Docker image for PR testing
|
|
- name: Build and push PR test image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./docker-s6/Dockerfile
|
|
platforms: ${{ steps.platforms.outputs.PLATFORMS }}
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
cache-from: type=gha
|
|
|
|
- name: Verify image build
|
|
run: |
|
|
echo "✅ PR Test Docker image built successfully"
|
|
echo "Images pushed:"
|
|
echo "${{ steps.meta.outputs.tags }}"
|
|
echo ""
|
|
echo "PR #${{ github.event.inputs.pr_number }} test image ready for testing"
|
|
echo "Platform(s): ${{ steps.platforms.outputs.PLATFORMS }}"
|
|
echo ""
|
|
echo "You can pull this image with:"
|
|
echo "docker pull ${{ secrets.DOCKER_USERNAME }}/trafegodns:pr-${{ github.event.inputs.pr_number }}"
|
|
echo "" |