From c055362810846977e1a5340a28f7db26a3a30a6d Mon Sep 17 00:00:00 2001 From: herryyun <3209851541@qq.com> Date: Thu, 11 Sep 2025 11:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20.gitea/workflows/build-ima?= =?UTF-8?q?ge.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/build-image.yml | 78 +++++++++++++++++++++++++++----- 1 file changed, 67 insertions(+), 11 deletions(-) diff --git a/.gitea/workflows/build-image.yml b/.gitea/workflows/build-image.yml index 9bc93ba..cc66791 100644 --- a/.gitea/workflows/build-image.yml +++ b/.gitea/workflows/build-image.yml @@ -23,17 +23,73 @@ jobs: runs-on: self_website steps: - - name: Test token with wget + - name: Checkout repository + uses: herryyun/checkout@v4 + with: + token: ${{ secrets.TOKEN }} + - name: Set Gradle version + id: gradle run: | - echo "Testing token authentication..." - wget -q --header="Authorization: token ${{ secrets.TOKEN }}" \ - --spider https://git.crash.work/api/v1/user || echo "wget test failed" - - - name: Test git access + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + GRADLE_VERSION="${{ github.event.inputs.gradle_version }}" + else + # 推送触发时使用默认版本 + GRADLE_VERSION="8.5" + fi + + echo "version=${GRADLE_VERSION}" >> $GITHUB_OUTPUT + echo "📦 使用Gradle版本: ${GRADLE_VERSION}" + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64 + build-args: | + GRADLE_VERSION=${{ steps.gradle.outputs.version }} + push: true + tags: | + ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:gradle${{ steps.gradle.outputs.version }} + ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest + labels: | + org.opencontainers.image.title=Gradle Dragonwell + org.opencontainers.image.description=Gradle ${{ steps.gradle.outputs.version }} with Alibaba Dragonwell 21 + org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} + org.opencontainers.image.revision=${{ github.sha }} + gradle.version=${{ steps.gradle.outputs.version }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Test built image run: | - echo "Testing git clone with token..." - git clone https://${{ secrets.TOKEN }}@git.crash.work/herryyun/checkout.git /tmp/test-checkout - ls -la /tmp/test-checkout - env: - GIT_TERMINAL_PROMPT: 0 + echo "🧪 测试构建的镜像..." + docker run --rm ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest java -version + docker run --rm ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest gradle --version + + - name: Generate summary + run: | + echo "## 🚀 镜像构建完成" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### 镜像信息" >> $GITHUB_STEP_SUMMARY + echo "- **Gradle版本**: ${{ steps.gradle.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "- **镜像名称**: \`${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}\`" >> $GITHUB_STEP_SUMMARY + echo "- **触发原因**: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "### 使用方法" >> $GITHUB_STEP_SUMMARY + echo '```bash' >> $GITHUB_STEP_SUMMARY + echo "docker pull ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_STEP_SUMMARY + echo "docker run --rm -v \$(pwd):/workspace -w /workspace \\" >> $GITHUB_STEP_SUMMARY + echo " ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest \\" >> $GITHUB_STEP_SUMMARY + echo " gradle build --no-daemon" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY