(refactor) restructure workflow into two jobs with dependency
Split the workflow into separate check_version and build jobs using the needs keyword for job dependencies. This improves separation of concerns and makes the workflow structure more explicit. Key changes: - Created check_version job that outputs version_changed and version - Build job now depends on check_version using needs keyword - Build job uses version from check_version output (no re-reading) - Added fetch-depth: 0 to ensure full git history for comparison - Removed duplicate version reading step from build job - Build conditional now uses needs.check_version.outputs.version_changed Benefits: - Clear separation between version checking and build logic - Version is determined once and reused across jobs - Better observability with separate job statuses in UI - Enables potential reuse of version outputs by other jobs Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,13 +11,17 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
check_version:
|
||||||
if: github.event_name == 'pull_request' || steps.version-check.outputs.version_changed == 'true'
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
version_changed: ${{ steps.version-check.outputs.version_changed }}
|
||||||
|
version: ${{ steps.version-check.outputs.version }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Check if version changed
|
- name: Check if version changed
|
||||||
id: version-check
|
id: version-check
|
||||||
@@ -25,6 +29,7 @@ jobs:
|
|||||||
# Get current version
|
# Get current version
|
||||||
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
CURRENT_VERSION=$(node -p "require('./package.json').version")
|
||||||
echo "Current version: $CURRENT_VERSION"
|
echo "Current version: $CURRENT_VERSION"
|
||||||
|
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
# Check if HEAD~1 exists (handle first commit)
|
# Check if HEAD~1 exists (handle first commit)
|
||||||
if ! git rev-parse HEAD~1 &>/dev/null; then
|
if ! git rev-parse HEAD~1 &>/dev/null; then
|
||||||
@@ -53,12 +58,14 @@ jobs:
|
|||||||
echo "version_changed=false" >> $GITHUB_OUTPUT
|
echo "version_changed=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Read package.json version
|
build:
|
||||||
id: package-version
|
needs: check_version
|
||||||
run: |
|
if: needs.check_version.outputs.version_changed == 'true' || github.event_name == 'pull_request'
|
||||||
VERSION=$(node -p "require('./package.json').version")
|
runs-on: ubuntu-latest
|
||||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
|
||||||
echo "Building version: $VERSION"
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v3
|
||||||
@@ -80,7 +87,7 @@ jobs:
|
|||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
registry.budakova.org/knee-cola/gitea-actions-demo-project:${{ steps.package-version.outputs.version }}
|
registry.budakova.org/knee-cola/gitea-actions-demo-project:${{ needs.check_version.outputs.version }}
|
||||||
registry.budakova.org/knee-cola/gitea-actions-demo-project:latest
|
registry.budakova.org/knee-cola/gitea-actions-demo-project:latest
|
||||||
cache-from: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache
|
cache-from: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache
|
||||||
cache-to: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache,mode=max
|
cache-to: type=registry,ref=registry.budakova.org/knee-cola/gitea-actions-demo-project:buildcache,mode=max
|
||||||
|
|||||||
Reference in New Issue
Block a user