chore: import upstream snapshot with attribution
This commit is contained in:
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/heads/main"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/build-buildtag"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/v.docker.nonsemver"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/v.docker.1.2.3"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/infra-prod-anything"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/infra-test-anything"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/1.2.3"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"ref": "refs/tags/standard-tag"
|
||||
}
|
||||
@@ -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) }}"
|
||||
Reference in New Issue
Block a user