refactor: remove redundant linux_builds_success logic in docker workflow (#235)

- Remove linux_builds_success output and related variables
- Simplify build-docker condition to only check should_build
- The should_build check already includes workflow success verification
- Reduce code complexity while maintaining the same functionality
This commit is contained in:
安正超
2025-07-17 05:09:41 +08:00
committed by GitHub
parent 1ea45afcd7
commit 5eb461d7b7

View File

@@ -27,10 +27,9 @@
name: Docker Images
# Permissions needed for workflow_run event and GitHub API access
# Permissions needed for workflow_run event and Docker registry access
permissions:
contents: read
actions: read
packages: write
on:
@@ -78,14 +77,13 @@ jobs:
short_sha: ${{ steps.check.outputs.short_sha }}
is_prerelease: ${{ steps.check.outputs.is_prerelease }}
create_latest: ${{ steps.check.outputs.create_latest }}
linux_builds_success: ${{ steps.check.outputs.linux_builds_success }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check build conditions and Linux build status
- name: Check build conditions
id: check
run: |
should_build=false
@@ -95,51 +93,20 @@ jobs:
short_sha=""
is_prerelease=false
create_latest=false
linux_builds_success=false
if [[ "${{ github.event_name }}" == "workflow_run" ]]; then
# Triggered by build workflow completion
echo "🔗 Triggered by build workflow completion"
# Check if the triggering workflow was successful
if [[ "${{ github.event.workflow_run.conclusion }}" != "success" ]]; then
echo "❌ Build workflow failed, skipping Docker build"
exit 0
fi
# Get workflow run details via GitHub API to check Linux build status
echo "🔍 Checking Linux build status from workflow run..."
# Use GitHub API to get detailed job information
WORKFLOW_RUN_ID="${{ github.event.workflow_run.id }}"
# Get jobs from the workflow run
echo "📡 Fetching job details for workflow run: $WORKFLOW_RUN_ID"
# Check if Linux builds were successful using GitHub API
JOBS_RESPONSE=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/$WORKFLOW_RUN_ID/jobs")
# Extract Linux build job status
LINUX_X64_SUCCESS=$(echo "$JOBS_RESPONSE" | jq -r '.jobs[] | select(.name | contains("x86_64-unknown-linux-musl")) | .conclusion')
LINUX_ARM64_SUCCESS=$(echo "$JOBS_RESPONSE" | jq -r '.jobs[] | select(.name | contains("aarch64-unknown-linux-musl")) | .conclusion')
echo "🐧 Linux build status:"
echo " x86_64: $LINUX_X64_SUCCESS"
echo " aarch64: $LINUX_ARM64_SUCCESS"
# Only proceed if both Linux builds are successful
if [[ "$LINUX_X64_SUCCESS" == "success" ]] && [[ "$LINUX_ARM64_SUCCESS" == "success" ]]; then
linux_builds_success=true
# If the workflow succeeded, it means ALL builds (including Linux x86_64 and aarch64) succeeded
if [[ "${{ github.event.workflow_run.conclusion }}" == "success" ]]; then
echo "✅ Build workflow succeeded, all builds including Linux are successful"
should_build=true
should_push=true
echo "✅ Both Linux builds successful, proceeding with Docker build"
else
linux_builds_success=false
echo "❌ Build workflow failed (conclusion: ${{ github.event.workflow_run.conclusion }}), skipping Docker build"
should_build=false
echo "❌ Linux builds not both successful, skipping Docker build"
echo " x86_64 status: $LINUX_X64_SUCCESS"
echo " aarch64 status: $LINUX_ARM64_SUCCESS"
fi
# Extract version info from commit message or use commit SHA
@@ -176,7 +143,6 @@ jobs:
input_version="${{ github.event.inputs.version }}"
version="${input_version}"
should_push="${{ github.event.inputs.push_images }}"
linux_builds_success=true # Assume true for manual builds
should_build=true
# Get short SHA
@@ -225,12 +191,6 @@ jobs:
esac
fi
# Only proceed if Linux builds were successful
if [[ "$linux_builds_success" != "true" ]]; then
echo "❌ Linux builds not successful, skipping Docker image build"
should_build=false
fi
echo "should_build=$should_build" >> $GITHUB_OUTPUT
echo "should_push=$should_push" >> $GITHUB_OUTPUT
echo "build_type=$build_type" >> $GITHUB_OUTPUT
@@ -238,7 +198,6 @@ jobs:
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
echo "is_prerelease=$is_prerelease" >> $GITHUB_OUTPUT
echo "create_latest=$create_latest" >> $GITHUB_OUTPUT
echo "linux_builds_success=$linux_builds_success" >> $GITHUB_OUTPUT
echo "🐳 Docker Build Summary:"
echo " - Should build: $should_build"
@@ -248,16 +207,15 @@ jobs:
echo " - Short SHA: $short_sha"
echo " - Is prerelease: $is_prerelease"
echo " - Create latest: $create_latest"
echo " - Linux builds success: $linux_builds_success"
# Build multi-arch Docker images
# Strategy: Build images using pre-built binaries from dl.rustfs.com
# Supports both release and dev channel binaries based on build context
# Only runs when Linux builds (x86_64 + aarch64) are successful
# Only runs when should_build is true (which includes workflow success check)
build-docker:
name: Build Docker Images
needs: build-check
if: needs.build-check.outputs.should_build == 'true' && needs.build-check.outputs.linux_builds_success == 'true'
if: needs.build-check.outputs.should_build == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
steps: