-
-
Notifications
You must be signed in to change notification settings - Fork 724
GitHub workflow improvements #1306
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
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
28050ad
lint and action updates
nicktrn 107b888
add custom image tag action
nicktrn fee02a4
remove publish infra bloat
nicktrn b2d1c3f
replace cancel action with native concurrency control
nicktrn 90f2f78
ignore all docs changes for release trigger
nicktrn f58df38
image action updates
nicktrn eef94fa
update publish trigger paths
nicktrn 8518b6f
simplify semver checks
nicktrn ce94909
make it possible to call publish
nicktrn cb87cb5
add tests for custom action
nicktrn d5b9167
rename publish workflows
nicktrn d36f047
call publish after successful package release
nicktrn 5df1b7e
fix inputs and published package parsing
nicktrn 483162a
clarify image tag action errors
nicktrn d2d0716
move test action
nicktrn db06c77
add test events
nicktrn 19f4a3c
add changesets action mock
nicktrn 404e18c
add docs checks
nicktrn 7c57d0e
add github action test readme
nicktrn ca14c69
fix docs check on push
nicktrn bee7a77
update action versions in docs
nicktrn acab9a8
cache npm for docs check
nicktrn ef7e3d9
pretend to fix bad docs link
nicktrn a7508f5
fix docs link
nicktrn ec642af
Revert "fix docs link"
nicktrn 698b244
Revert "Revert "fix docs link""
nicktrn 066ed5a
improve caching
nicktrn 2dafb71
Merge branch 'main' into workflow-improvements
nicktrn 07e15af
disable automatic publishing after release
nicktrn 0910b71
limit docs checks to pushes to main and PRs
nicktrn aded298
fix broken links
nicktrn 65c7b89
prevent word splitting and globbing
nicktrn 2b5e085
use latest checkout action everywhere
nicktrn 0dcf8f2
correctly detect prereleases as valid semver
nicktrn 30e94e2
update to latest cache action
nicktrn 679ec0a
Merge branch 'main' into workflow-improvements
nicktrn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
name: "#️⃣ Get image tag (action)" | ||
|
||
description: This action gets the image tag from the commit ref or input (if provided) | ||
|
||
outputs: | ||
tag: | ||
description: The image tag | ||
value: ${{ steps.get_tag.outputs.tag }} | ||
is_semver: | ||
description: Whether the tag is a semantic version | ||
value: ${{ steps.check_semver.outputs.is_semver }} | ||
|
||
inputs: | ||
tag: | ||
description: The image tag. If this is set it will return the tag as is. | ||
required: false | ||
default: "" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: "#️⃣ Get image tag (step)" | ||
id: get_tag | ||
shell: bash | ||
run: | | ||
if [[ -n "${{ inputs.tag }}" ]]; then | ||
tag="${{ inputs.tag }}" | ||
elif [[ "${{ github.ref_type }}" == "tag" ]]; then | ||
if [[ "${{ github.ref_name }}" == infra-*-* ]]; then | ||
env=$(echo ${{ github.ref_name }} | cut -d- -f2) | ||
sha=$(echo ${{ github.sha }} | head -c7) | ||
ts=$(date +%s) | ||
tag=${env}-${sha}-${ts} | ||
elif [[ "${{ github.ref_name }}" == v.docker.* ]]; then | ||
version="${GITHUB_REF_NAME#v.docker.}" | ||
tag="v${version}" | ||
elif [[ "${{ github.ref_name }}" == build-* ]]; then | ||
tag="${GITHUB_REF_NAME#build-}" | ||
else | ||
echo "Invalid git tag: ${{ github.ref_name }}" | ||
exit 1 | ||
fi | ||
elif [[ "${{ github.ref_name }}" == "main" ]]; then | ||
tag="main" | ||
else | ||
echo "Invalid git ref: ${{ github.ref }}" | ||
exit 1 | ||
fi | ||
echo "tag=${tag}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: 🔍 Check for validity | ||
id: check_validity | ||
shell: bash | ||
env: | ||
tag: ${{ steps.get_tag.outputs.tag }} | ||
run: | | ||
if [[ "${tag}" =~ ^[a-z0-9]+([._-][a-z0-9]+)*$ ]]; then | ||
echo "Tag is valid: ${tag}" | ||
else | ||
echo "Tag is not valid: ${tag}" | ||
exit 1 | ||
fi | ||
nicktrn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- name: 🆚 Check for semver | ||
id: check_semver | ||
shell: bash | ||
env: | ||
tag: ${{ steps.get_tag.outputs.tag }} | ||
# Will match most semver formats except build metadata, i.e. v1.2.3+build.1 | ||
# Valid matches: | ||
# v1.2.3 | ||
# v1.2.3-alpha | ||
# v1.2.3-alpha.1 | ||
# v1.2.3-rc.1 | ||
# v1.2.3-beta-1 | ||
run: | | ||
if [[ "${tag}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then | ||
echo "Tag is a semantic version: ${tag}" | ||
is_semver=true | ||
else | ||
echo "Tag is not a semantic version: ${tag}" | ||
is_semver=false | ||
fi | ||
echo "is_semver=${is_semver}" >> "$GITHUB_OUTPUT" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# GitHub Action Tests | ||
|
||
This directory contains necessary files to allow local testing of GitHub Actions workflows, composite actions, etc. You will need to install [act](https://github.com/nektos/act) to perform tests. | ||
|
||
## Workflow tests | ||
|
||
Trigger specific workflow files by specifying their full path: | ||
|
||
``` | ||
act -W .github/workflow/release.yml | ||
``` | ||
|
||
You will likely need to override any custom runners we use, e.g. buildjet. For example: | ||
|
||
``` | ||
override=catthehacker/ubuntu:act-latest | ||
|
||
act -W .github/workflow/release.yml \ | ||
-P buildjet-8vcpu-ubuntu-2204=$override | ||
|
||
# override multiple images at the same time | ||
act -W .github/workflow/release.yml \ | ||
-P buildjet-8vcpu-ubuntu-2204=$override \ | ||
-P buildjet-16vcpu-ubuntu-2204=$override | ||
``` | ||
|
||
Trigger with specific event payloads to test pushing to branches or tags: | ||
|
||
``` | ||
override=catthehacker/ubuntu:act-latest | ||
|
||
# simulate push to main | ||
act -W .github/workflow/publish.yml \ | ||
-P buildjet-8vcpu-ubuntu-2204=$override \ | ||
-P buildjet-16vcpu-ubuntu-2204=$override \ | ||
-e .github/events/push-tag-main.json | ||
|
||
# simulate a `build-` prefixed tag | ||
act -W .github/workflow/publish.yml \ | ||
-P buildjet-8vcpu-ubuntu-2204=$override \ | ||
-P buildjet-16vcpu-ubuntu-2204=$override \ | ||
-e .github/events/push-tag-buld.json | ||
``` | ||
|
||
By default, `act` will send a push event. To trigger a different event: | ||
|
||
``` | ||
# basic syntax | ||
act <EVENT> ... | ||
|
||
# simulate a pull request | ||
act pull_request | ||
|
||
# only trigger a specific workflow | ||
act pull_request -W .github/workflow/pr_checks.yml | ||
``` | ||
|
||
## Composite action tests | ||
|
||
The composite (custom) action tests can be run by triggering the `test-actions` workflow: | ||
|
||
``` | ||
act -W .github/test/test-actions.yml | ||
``` | ||
|
||
## Helpful flags | ||
|
||
- `--pull=false` - perform fully offline tests if all images are already present | ||
- `-j <job_name>` - run the specified job only | ||
- `-l push` - list all workflows with push triggers | ||
nicktrn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/heads/main" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/build-buildtag" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/v.docker.nonsemver" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/v.docker.1.2.3" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/infra-prod-anything" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/infra-test-anything" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/1.2.3" | ||
} | ||
nicktrn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"ref": "refs/tags/standard-tag" | ||
} | ||
nicktrn marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
name: Test Actions | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
get-image-tag-none: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log current ref | ||
run: | | ||
echo "ref: ${{ github.ref }}" | ||
echo "ref_type: ${{ github.ref_type }}" | ||
echo "ref_name: ${{ github.ref_name }}" | ||
|
||
- name: Run without input tag | ||
id: get_tag | ||
# this step may fail depending on the current ref | ||
continue-on-error: true | ||
uses: ./.github/actions/get-image-tag | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-null: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log current ref | ||
run: | | ||
echo "ref: ${{ github.ref }}" | ||
echo "ref_type: ${{ github.ref_type }}" | ||
echo "ref_name: ${{ github.ref_name }}" | ||
|
||
- name: Run without input tag | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
# this step may fail depending on the current ref | ||
continue-on-error: true | ||
with: | ||
# this should behave exactly as when no tag is provided | ||
tag: null | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-override: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run with tag override | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
with: | ||
tag: "abc-123" | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-invalid-string: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run with invalid string | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
# this step is expected to fail | ||
continue-on-error: true | ||
with: | ||
# does not end with alphanumeric character | ||
tag: "abc-123-" | ||
|
||
- name: Fail job if previous step did not fail | ||
if: steps.get_tag.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-prerelease: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run with prerelease semver | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
with: | ||
tag: "v1.2.3-beta.4" | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-semver: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run with basic semver | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
with: | ||
tag: "v1.2.3" | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" | ||
|
||
get-image-tag-invalid-semver: | ||
runs-on: ubuntu-latest | ||
continue-on-error: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Run with invalid semver | ||
id: get_tag | ||
uses: ./.github/actions/get-image-tag | ||
# this step is expected to fail | ||
continue-on-error: true | ||
with: | ||
tag: "v1.2.3-" | ||
|
||
- name: Fail job if previous step did not fail | ||
if: steps.get_tag.outcome != 'failure' | ||
run: exit 1 | ||
|
||
- name: Verify output | ||
run: | | ||
echo "${{ toJson(steps.get_tag) }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
name: 📚 Docs Checks | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- "docs/**" | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
paths: | ||
- "docs/**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
check-broken-links: | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./docs | ||
steps: | ||
- name: 📥 Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: 📦 Cache npm | ||
uses: actions/cache@v4 | ||
with: | ||
path: | | ||
~/.npm | ||
key: | | ||
${{ runner.os }}-mintlify | ||
restore-keys: | | ||
${{ runner.os }}-mintlify | ||
|
||
- name: 🔗 Check for broken links | ||
run: npx mintlify@4.0.222 broken-links |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.