Skip to content

Commit

Permalink
Merge pull request #323 from boxuk/workflow-trigggers
Browse files Browse the repository at this point in the history
Fixes for workflow triggers
  • Loading branch information
jdamner authored Jan 17, 2025
2 parents f8c5d03 + d5ac6bd commit 08b31b7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/all-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
uses: boxuk/wp-checkout-deps-auto-update@main
id: checkout-deps
if: github.event_name == 'workflow_run'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: GitHub Checks
uses: poseidon/[email protected]
Expand All @@ -28,4 +30,5 @@ jobs:
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ jobs:
uses: boxuk/checkout-pr@main
id: checkout-deps
if: github.event_name == 'workflow_run'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node
uses: actions/setup-node@v4
Expand All @@ -64,4 +66,5 @@ jobs:
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
github-token: ${{ secrets.GITHUB_TOKEN }}

6 changes: 6 additions & 0 deletions packages/action-checkout-pr/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Checkout WP Deps Branch
description: Checkout a branch for the WP Deps update action

inputs:
github-token:
description: 'GitHub Token'
required: true

outputs:
pr-head-sha:
Expand Down Expand Up @@ -63,4 +68,5 @@ runs:
with:
status: "pending"
pr-head-sha: ${{ steps.parse-pr-number.outputs.PR_HEAD_SHA }}
github-token: ${{ inputs.github-token }}

5 changes: 4 additions & 1 deletion packages/action-mark-check-status/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ inputs:
default: 'pending'
pr-head-sha:
description: 'The SHA of the head of the PR'
github-token:
description: 'The GitHub token to use'
required: true

runs:
using: composite
steps:
- name: Set Check Status
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_TOKEN: ${{ inputs.github-token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ inputs.pr-head-sha }} \
-f state=${{ inputs.status }} \
Expand Down
32 changes: 32 additions & 0 deletions workflow-cacl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const workflows = [
// { cost: 100, frequency: 0.9 }, // PHP Tests?
{ cost: 90, frequency: 0.9 }, // JS Tests?
{ cost: 30, frequency: 0.5 }, // Other Tests?
{ cost: 30, frequency: 0.3 }, // Build
{ cost: 200, frequency: 0.1 }, // VR Tests?
];

const run = () => {
let currentCost = 0;
let optimisedCost = 0;
let runnerCost = 0;

workflows.map( workflow => currentCost += workflow.cost );
workflows.map( workflow => {
optimisedCost += Math.random() < workflow.frequency ? workflow.cost : 0;
runnerCost = workflow.cost > runnerCost ? workflow.cost : runnerCost;
} )
optimisedCost += runnerCost;
return currentCost > optimisedCost;
}

const runCount = 10000;
let optimisedWinsCount = 0;

for(let i = 0; i <= runCount; i++) {
if ( run() ) {
optimisedWinsCount++;
}
}

console.log( `Optimised wins: ${Math.round(optimisedWinsCount / runCount * 100)}%` );

0 comments on commit 08b31b7

Please sign in to comment.