Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions .github/workflows/deploy-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
get-base-sha:
runs-on: ubuntu-latest
outputs:
base_sha: ${{ steps.last_successful_workflow_dispatch_run.outputs.base_sha }}
base_sha: ${{ steps.last-successful-deploy.outputs.base_sha }}
steps:
- name: Get last successful workflow_dispatch run
id: last_successful_workflow_dispatch_run
- name: Get last successful deploy
id: last-successful-deploy
uses: actions/github-script@v8
with:
script: |
Expand All @@ -34,17 +34,23 @@ jobs:
repo,
workflow_id: workflowId,
branch: branch,
event: 'workflow_dispatch',
status: 'success',
per_page: 1,
});
if (workflowRuns.data.workflow_runs.length > 0) {
core.setOutput('base_sha', workflowRuns.data.workflow_runs[0].head_sha);
const lastSuccessfulRun = workflowRuns.data.workflow_runs[0];
console.log(`Last successful deploy on branch '${branch}':`);
console.log(`ID: ${lastSuccessfulRun.id}`);
console.log(`Commit SHA: ${lastSuccessfulRun.head_sha}`);
console.log(`Run URL: ${lastSuccessfulRun.html_url}`);
core.setOutput('base_sha', lastSuccessfulRun.head_sha);
} else {
console.log(`No successful deploys found on branch '${branch}' for workflow '${workflowId}'.`);
core.setOutput('base_sha', '');
}
} catch (error) {
console.log(`Error fetching workflow runs: ${error.message}`);
console.log(`Workflow '${workflowId}' may not exist in this repository. Defaulting base to empty string.`);
core.setOutput('base_sha', '');
}

Expand Down Expand Up @@ -126,8 +132,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Checkout Scripts Repo
uses: actions/checkout@v6
Expand All @@ -143,6 +147,10 @@ jobs:
id: get-head-sha
run: echo "head_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- name: Unshallow repository
if: needs.set-state.outputs.deploy_all == 'false' && needs.set-state.outputs.base_sha != ''
run: git fetch --unshallow 2>/dev/null || true

- name: Get changed files in the src/pages folder
if: needs.set-state.outputs.deploy_all == 'false'
id: changed-files-specific
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Checkout Scripts Repo
uses: actions/checkout@v6
Expand All @@ -126,8 +124,8 @@ jobs:
path: scripts
ref: main

- name: Get last successful workflow_dispatch run
id: last_successful_workflow_dispatch_run
- name: Get last successful deploy
id: last-successful-deploy
uses: actions/github-script@v8
with:
script: |
Expand All @@ -141,20 +139,19 @@ jobs:
repo,
workflow_id: workflowId,
branch: branch,
event: 'workflow_dispatch',
status: 'success',
per_page: 1, // Only need the latest one
});

if (workflowRuns.data.workflow_runs.length > 0) {
const lastSuccessfulRun = workflowRuns.data.workflow_runs[0];
console.log(`Last successful workflow_dispatch run on branch '${branch}':`);
console.log(`Last successful deploy on branch '${branch}':`);
console.log(`ID: ${lastSuccessfulRun.id}`);
console.log(`Commit SHA: ${lastSuccessfulRun.head_sha}`);
console.log(`Run URL: ${lastSuccessfulRun.html_url}`);
core.setOutput('base', lastSuccessfulRun.head_sha);
} else {
console.log(`No successful workflow_dispatch runs found on branch '${branch}' for workflow '${workflowId}'.`);
console.log(`No successful deploys found on branch '${branch}' for workflow '${workflowId}'.`);
core.setOutput('base', '');
}
} catch (error) {
Expand All @@ -163,6 +160,14 @@ jobs:
core.setOutput('base', '');
}

- name: Resolve base SHA
id: resolve-base-sha
run: echo "sha=${{ needs.set-state.outputs.base_Sha || steps.last-successful-deploy.outputs.base }}" >> "$GITHUB_OUTPUT"

- name: Unshallow repository
if: needs.set-state.outputs.deploy_All == 'false' && steps.resolve-base-sha.outputs.sha != ''
run: git fetch --unshallow 2>/dev/null || true

- name: Get changed files in the src/pages folder
if: needs.set-state.outputs.deploy_All == 'false'
id: changed-files-specific
Expand All @@ -172,7 +177,7 @@ jobs:
escape_json: false
files: |
src/pages/**
base_sha: ${{ needs.set-state.outputs.base_Sha || steps.last_successful_workflow_dispatch_run.outputs.base }}
base_sha: ${{ steps.resolve-base-sha.outputs.sha }}

- name: Get all files from src/pages folder
if: needs.set-state.outputs.deploy_All == 'true'
Expand Down