build gitea release/v1.22🚀 with linux/arm/v6 #22
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: "gitea" | |
repo_url: | |
description: "Repository URL" | |
required: false | |
default: "https://github.com/go-gitea/gitea.git" | |
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: build ${{ github.event.inputs.project_name }} ${{ github.event.inputs.version }}🚀 with ${{ github.event.inputs.platforms }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout based on input URL | |
run: | | |
echo "Cloning from URL: ${{ github.event.inputs.repo_url }}" | |
git clone ${{ github.event.inputs.repo_url }} . | |
- 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=$(echo "$SAFE_VERSION" | sed -E 's/^[^0-9]*([0-9].*)/\1/') | |
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 }} |