Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BWP-122] Triggering the Test Workflows #322

Merged
merged 1 commit into from
Jan 17, 2025
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
15 changes: 13 additions & 2 deletions .github/workflows/all-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,26 @@ on:
workflows: ["Update WP Deps"]
types:
- completed


jobs:
enforce-all-checks:
runs-on: ubuntu-latest
permissions:
checks: read
steps:
- name: Checkout
uses: boxuk/wp-checkout-deps-auto-update@main
id: checkout-deps
if: github.event_name == 'workflow_run'

- name: GitHub Checks
uses: poseidon/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Mark Check Outcome
if: github.event_name == 'workflow_run'
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
8 changes: 5 additions & 3 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ jobs:
target_repo: "wp-consent-management"
- local_path: "email-tld-checker"
target_repo: "wordpress-email-tld-checker"
- local_path: "deps-auto-update"
- local_path: "action-deps-auto-update"
target_repo: "wp-deps-auto-update"
- local_path: "checkout-deps-auto-update"
target_repo: "wp-checkout-deps-auto-update"
- local_path: "action-checkout-pr"
target_repo: "checkout-pr"
- local_path: "action-mark-check-status"
target_repo: "mark-check-status"
- local_path: "feature-flags"
target_repo: "wp-feature-flags"

Expand Down
44 changes: 9 additions & 35 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,10 @@ jobs:
if: github.event_name != 'workflow_run'

- name: Checkout
uses: boxuk/wp-checkout-deps-auto-update@main
uses: boxuk/checkout-pr@main
id: checkout-deps
if: github.event_name == 'workflow_run'
with:
workflow_run_id: ${{ github.event.workflow_run.id }}

- name: Mark Check as Pending
if: github.event_name == 'workflow_run'
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.checkout-deps.outputs.pr-head-sha }} \
-f state=pending \
-f description="JS Quality Tests are in progress" \
-f context="JS Quality Tests"


- name: Setup Node
uses: actions/setup-node@v4
with:
Expand All @@ -70,24 +58,10 @@ jobs:
- name: Build
run: npm run build

- name: Mark Check as Success
if: github.event_name == 'workflow_run' && success()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.checkout-deps.outputs.pr-head-sha }} \
-f state=success \
-f target_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \
-f description="JS Quality Tests completed successfully" \
-f context="JS Quality Tests"

- name: Mark Check as Failure
if: github.event_name == 'workflow_run' && failure()
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ steps.checkout-deps.outputs.pr-head-sha }} \
-f state=failure \
-f target_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \
-f description="JS Quality Tests failed" \
-f context="JS Quality Tests"
- name: Mark Check Outcome
if: github.event_name == 'workflow_run'
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}

Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: Checkout WP Deps Branch
description: Checkout a branch for the WP Deps update action

inputs:
workflow_run_id:
description: 'The ID of the workflow run that triggered this action'
required: true

outputs:
pr-head-sha:
Expand All @@ -23,7 +18,7 @@ runs:
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ inputs.workflow_run_id }},
run_id: ${{ github.event.workflow_run.id }},
});

if ( allArtifacts.data.total_count == 0 || allArtifacts.data.artifacts.length == 0 ) {
Expand Down Expand Up @@ -61,4 +56,11 @@ runs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ env.PR_HEAD_SHA }}
ref: ${{ steps.parse-pr-number.outputs.PR_HEAD_SHA }}

- name: Mark Check Pending
uses: boxuk/mark-check-status@main
with:
status: "pending"
pr-head-sha: ${{ steps.parse-pr-number.outputs.PR_HEAD_SHA }}

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a simple GitHub Worklfow to checkout the PR the `boxuk/wp-deps-auto-upda

## Usage

You'll need to use the `boxuk/wp-checkout-deps-auto-update` action to setup your workflow if the event is triggered by `workflow_run`. We need the `worfklow_run_id` to pull the relevant PR number.
You'll need to use the `boxuk/checkout-pr` action to setup your workflow if the event is triggered by `workflow_run`. We need the `worfklow_run_id` to pull the relevant PR number.

```yml
# Other config...
Expand All @@ -25,12 +25,18 @@ jobs:
if: github.event_name != 'workflow_run'

- name: Checkout
uses: boxuk/wp-checkout-deps-auto-update@main
uses: boxuk/checkout-pr@main
id: checkout-deps
if: github.event_name == 'workflow_run'
with:
workflow_run_id: ${{ github.event.workflow_run.id }}

# next steps...

# Run Tests or whatever is needed...

- name: Mark Check Outcome
if: github.event_name == 'workflow_run'
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

This will save the PR number created, so you can use it later for triggering tests etc.

For any other tests etc that you may need to have completed upon creation of this PR, you can then use the `boxuk/wp-checkout-deps-auto-update` action to setup your tests.
For any other tests etc that you may need to have completed upon creation of this PR, you can then use the `boxuk/wp-checkout-pr` action to setup your tests.

```yml
# Other config...
Expand All @@ -63,12 +63,18 @@ jobs:
if: github.event_name != 'workflow_run'

- name: Checkout
uses: boxuk/wp-checkout-deps-auto-update@main
uses: boxuk/checkout-pr@main
id: checkout-deps
if: github.event_name == 'workflow_run'
with:
workflow_run_id: ${{ github.event.workflow_run.id }}

# next steps...
# Run Tests or whatever is needed...

- name: Mark Check Outcome
if: github.event_name == 'workflow_run'
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
```

# Setting up your Project for WP Packages
Expand Down
24 changes: 24 additions & 0 deletions packages/action-mark-check-status/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Mark Check Status
description: Marks a check status for a given PR

inputs:
status:
description: 'The status to set'
required: true
default: 'pending'
pr-head-sha:
description: 'The SHA of the head of the PR'

runs:
using: composite
steps:
- name: Set Check Status
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
gh api repos/${{ github.repository }}/statuses/${{ inputs.pr-head-sha }} \
-f state=${{ inputs.status }} \
-f target_url=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \
-f context="${{ github.workflow }}" \
-f description="${{ github.workflow }}"
50 changes: 50 additions & 0 deletions packages/action-mark-check-status/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# WordPress Deps Auto Updater - Checkout

This is a simple GitHub Worklfow to mark the state of a status-check that's been triggered via the `workflow_run` trigger.

## Usage

You'll need to use the `boxuk/checkout-pr` action to setup your workflow if the event is triggered by `workflow_run`. We need the `worfklow_run_id` to pull the relevant PR number.

```yml
# Other config...
on:
pull_request: # For all PRs
workflow_run: # For WP Updates
workflows: ["Update WP Deps"]
types:
- completed

jobs:
test:
runs-on: ubuntu-latest
name: Test
steps:
- name: Checkout
uses: actions/checkout@v4
if: github.event_name != 'workflow_run'

- name: Checkout
uses: boxuk/checkout-pr@main
id: checkout-deps
if: github.event_name == 'workflow_run'

# Run Tests or whatever is needed...

- name: Mark Check Outcome
if: github.event_name == 'workflow_run'
uses: boxuk/mark-check-status@main
with:
status: ${{ job.status }}
pr-head-sha: ${{ steps.checkout-deps.outputs.pr-head-sha }}
```

## Contributing

Please do not submit any Pull Requests here. They will be closed.
---

Please submit your PR here instead: https://github.com/boxuk/wp-packages

This repository is what we call a "subtree split": a read-only subset of that main repository.
We're looking forward to your PR there!
Loading