jackadam1981 is testing build 🚀 #7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Build and push what you want" | |
on: | |
workflow_dispatch: | |
inputs: | |
project_name: | |
description: "Project name (e.g., owner/repo)" | |
required: false | |
default: "go-gitea/gitea" | |
repo_url: | |
description: "Repository URL" | |
required: false | |
default: "" | |
platforms: | |
description: "Platforms (comma-separated, e.g., linux/amd64,linux/arm64)" | |
required: true | |
default: "linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6" | |
version: | |
description: 'Version (branch, tag, or commit hash)' | |
required: false | |
default: 'main' # 默认使用主分支 | |
run-name: ${{ github.actor }} is testing build ${{ github.event.inputs.project }} 🚀 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout based on input | |
run: | | |
if [ -n "${{ github.event.inputs.repo_url }}" ]; then | |
echo "Cloning from URL: ${{ github.event.inputs.repo_url }}" | |
git clone ${{ github.event.inputs.repo_url }} . | |
elif [ -n "${{ github.event.inputs.project_name }}" ]; then | |
echo "Cloning from project name: ${{ github.event.inputs.project_name }}" | |
git clone https://github.com/${{ github.event.inputs.project_name }}.git . | |
else | |
echo "No valid input provided. Please provide either a project name or a repository URL." | |
exit 1 | |
fi | |
- name: Checkout specified version | |
run: | | |
git fetch --all | |
git checkout ${{ github.event.inputs.version }} | |
- name: Prepare Docker tags | |
id: prepare_tags | |
run: | | |
SAFE_VERSION="${{ github.event.inputs.version }}" | |
SAFE_VERSION="${SAFE_VERSION//\//_}" | |
echo "safe_version=$SAFE_VERSION" >> $GITHUB_ENV | |
- name: Set tag | |
id: tag | |
run: | | |
if [[ -n $(cat ${{ github.event.inputs.project }}/Dockerfile | awk '{if($1~"ENV" && $2=="VERSION")print $3}') ]]; then | |
VERSION=$(cat ${{ github.event.inputs.project }}/Dockerfile | awk '{if($1~"ENV" && $2=="VERSION")print $3}') | |
echo "tag=$VERSION" >> $GITHUB_ENV | |
else | |
echo "tag=$(date +%Y)-$(date +%m)-$(date +%d)" >> $GITHUB_ENV | |
fi | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: 登录 docker | |
uses: docker/login-action@v3 | |
with: | |
#设置两个secrets: docker的用户名和密码 | |
username: "${{ secrets.DOCKERHUB_USERNAME }}" | |
password: "${{ secrets.DOCKERHUB_PASSWORD }}" | |
- name: Build and push to docker hub | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: ${{ github.event.inputs.platforms }} | |
push: true | |
tags: | | |
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.inputs.project_name }}:${{ env.safe_version }} |