10 KiB
title, shortTitle, intro, versions, type, topics
| title | shortTitle | intro | versions | type | topics | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Using scripts to test your code on a runner | Use scripts to test your code on a runner | How to use essential {% data variables.product.prodname_actions %} features for continuous integration (CI). |
|
how_to |
|
{% data reusables.actions.enterprise-github-hosted-runners %}
Example overview
{% data reusables.actions.example-workflow-intro-ci %} When this workflow is triggered, it automatically runs a script that checks whether the {% data variables.product.prodname_dotcom %} Docs site has any broken links.
{% data reusables.actions.example-diagram-intro %}
Features used in this example
{% data reusables.actions.example-table-intro %}
| Feature | Implementation |
|---|---|
| {% data reusables.actions.push-table-entry %} | |
| {% data reusables.actions.pull-request-table-entry %} | |
| {% data reusables.actions.workflow-dispatch-table-entry %} | |
| {% data reusables.actions.permissions-table-entry %} | |
| {% data reusables.actions.concurrency-table-entry %} | |
| Running the job on different runners, depending on the repository | runs-on |
| {% data reusables.actions.checkout-action-table-entry %} | |
| {% data reusables.actions.setup-node-table-entry %} | |
| Using a third-party action | trilom/file-changes-action |
| Running a script on the runner | Using ./script/rendered-content-link-checker.mjs |
Example workflow
{% data reusables.actions.example-docs-engineering-intro %} check-broken-links-github-github.yml.
{% data reusables.actions.note-understanding-example %}
name: 'Link Checker: All English'
# **What it does**: Renders the content of every page and check all internal links.
# **Why we have it**: To make sure all links connect correctly.
# **Who does it impact**: Docs content.
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
permissions:
contents: read
# Needed for the 'trilom/file-changes-action' action
pull-requests: read
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: {% raw %}'${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'{% endraw %}
cancel-in-progress: true
jobs:
check-links:
runs-on: {% raw %}${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}{% endraw %}
steps:
- name: Checkout
uses: {% data reusables.actions.action-checkout %}
- name: Setup node
uses: {% data reusables.actions.action-setup-node %}
with:
node-version: 16.13.x
cache: npm
- name: Install
run: npm ci
# Creates file "${{ env.HOME }}/files.json", among others
- name: Gather files changed
uses: trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b
with:
fileOutput: 'json'
# For verification
- name: Show files changed
run: cat $HOME/files.json
- name: Link check (warnings, changed files)
run: |
./script/rendered-content-link-checker.mjs \
--language en \
--max 100 \
--check-anchors \
--check-images \
--verbose \
--list $HOME/files.json
- name: Link check (critical, all files)
run: |
./script/rendered-content-link-checker.mjs \
--language en \
--exit \
--verbose \
--check-images \
--level critical
Understanding the example
{% data reusables.actions.example-explanation-table-intro %}
| Code | Explanation |
|---|---|
|
{% data reusables.actions.explanation-name-key %} |
|
The |
|
Add the |
|
Add the |
|
Add the |
|
Modifies the default permissions granted to |
|
{% raw %} {% endraw %} |
Creates a concurrency group for specific events, and uses the |
|
Cancels any currently running job or workflow in the same concurrency group. |
|
Groups together all the jobs that run in the workflow file. |
|
Defines a job with the ID |
|
{% raw %} {% endraw %} |
Configures the job to run on a {% data variables.product.prodname_dotcom %}-hosted runner or a self-hosted runner, depending on the repository running the workflow. In this example, the job will run on a self-hosted runner if the repository is named |
|
Groups together all the steps that will run as part of the |
|
The |
|
This step uses the |
|
The |
|
Uses the |
|
Lists the contents of |
|
This step uses |
|
This step also uses |
Next steps
{% data reusables.actions.learning-actions %}
