From c3ffdc90c8819e1e7c70fb66ab4a5bb20d5fe871 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:01:09 -0600 Subject: [PATCH 01/17] implement base workflow list acceptance test --- acceptance/acceptance_test.go | 29 +++++++++++ .../testdata/workflow/workflow-list.txtar | 52 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 acceptance/testdata/workflow/workflow-list.txtar diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index cbd59b761..e390f2247 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -6,8 +6,10 @@ import ( "fmt" "os" "path" + "strconv" "strings" "testing" + "time" "math/rand" @@ -35,6 +37,16 @@ func TestPullRequests(t *testing.T) { testscript.Run(t, testScriptParamsFor(tsEnv, "pr")) } +func TestWorkflows(t *testing.T) { + var tsEnv testScriptEnv + if err := tsEnv.fromEnv(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + testscript.Run(t, testScriptParamsFor(tsEnv, "workflow")) +} + func testScriptParamsFor(tsEnv testScriptEnv, command string) testscript.Params { var files []string if tsEnv.script != "" { @@ -119,6 +131,23 @@ func sharedCmds(tsEnv testScriptEnv) map[string]func(ts *testscript.TestScript, ts.Setenv(args[0], strings.TrimRight(ts.ReadFile("stdout"), "\n")) }, + "sleep": func(ts *testscript.TestScript, neg bool, args []string) { + if neg { + ts.Fatalf("unsupported: ! sleep") + } + if len(args) != 1 { + ts.Fatalf("usage: sleep seconds") + } + + // sleep for the given number of seconds + seconds, err := strconv.Atoi(args[0]) + if err != nil { + ts.Fatalf("invalid number of seconds: %v", err) + } + + d := time.Duration(seconds) * time.Second + time.Sleep(d) + }, } } diff --git a/acceptance/testdata/workflow/workflow-list.txtar b/acceptance/testdata/workflow/workflow-list.txtar new file mode 100644 index 000000000..8cd211de0 --- /dev/null +++ b/acceptance/testdata/workflow/workflow-list.txtar @@ -0,0 +1,52 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: sleep 10 From 5f919bc5b0f931d19c26ff9d8b648a23468c0358 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:01:21 -0600 Subject: [PATCH 02/17] implement workflow enable/disable acceptance test --- .../workflow/workflow-enable-disable.txtar | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 acceptance/testdata/workflow/workflow-enable-disable.txtar diff --git a/acceptance/testdata/workflow/workflow-enable-disable.txtar b/acceptance/testdata/workflow/workflow-enable-disable.txtar new file mode 100644 index 000000000..c248c1cad --- /dev/null +++ b/acceptance/testdata/workflow/workflow-enable-disable.txtar @@ -0,0 +1,71 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# disable the workflow +exec gh workflow disable 'Test Workflow Name' + +# Check the workflow is indeed disabled +# Disabled workflows are hidden by default. +exec gh workflow list +stdout '' + +# Check that the listing shows it is disabled +exec gh workflow list --all +stdout 'Test\s+Workflow\s+Name\s+disabled_manually\s+\d+' + +# enable the workflow +exec gh workflow enable 'Test Workflow Name' + +# Check the workflow is indeed enabled +exec gh workflow list +stdout 'Test Workflow Name' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: sleep 10 From 0b1d6923e1f8d660482c838bbfed7e1233309926 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:37:06 -0600 Subject: [PATCH 03/17] Create workflow-view.txtar --- .../testdata/workflow/workflow-view.txtar | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 acceptance/testdata/workflow/workflow-view.txtar diff --git a/acceptance/testdata/workflow/workflow-view.txtar b/acceptance/testdata/workflow/workflow-view.txtar new file mode 100644 index 000000000..0783e7fac --- /dev/null +++ b/acceptance/testdata/workflow/workflow-view.txtar @@ -0,0 +1,52 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow view 'Test Workflow Name' +stdout 'Test Workflow Name - workflow.yml' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: sleep 10 From 3737f10246ac9be516f9059a4eb308bbaa91447a Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:37:11 -0600 Subject: [PATCH 04/17] Create workflow-run.txtar --- .../testdata/workflow/workflow-run.txtar | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 acceptance/testdata/workflow/workflow-run.txtar diff --git a/acceptance/testdata/workflow/workflow-run.txtar b/acceptance/testdata/workflow/workflow-run.txtar new file mode 100644 index 000000000..7e9a823ee --- /dev/null +++ b/acceptance/testdata/workflow/workflow-run.txtar @@ -0,0 +1,62 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Check the workflow run exists +exec gh run list +stdout 'Test Workflow Name' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! From 446ffede1281359c0e4edc143a80321332c28dda Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 11:37:14 -0600 Subject: [PATCH 05/17] Create run-cancel.txtar --- acceptance/testdata/workflow/run-cancel.txtar | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 acceptance/testdata/workflow/run-cancel.txtar diff --git a/acceptance/testdata/workflow/run-cancel.txtar b/acceptance/testdata/workflow/run-cancel.txtar new file mode 100644 index 000000000..f06912c90 --- /dev/null +++ b/acceptance/testdata/workflow/run-cancel.txtar @@ -0,0 +1,73 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to cancel +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# cancel the workflow run +exec gh run cancel $RUN_ID +stdout '✓ Request to cancel workflow [0-9]+ submitted.' + +# It takes some time for a workflow run to be cancelled +sleep 5 + +# Check the workflow run is cancelled +exec gh run list --json conclusion --jq '.[0].conclusion' +stdout 'cancelled' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v4 + + # Runs a single command using the runners shell + - name: Run a one-line script + run: sleep 30 From 3f080e0948dc8d5e88a3e8b3104ab10486348534 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:19:44 -0600 Subject: [PATCH 06/17] Create run-delete.txtar --- acceptance/testdata/workflow/run-delete.txtar | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 acceptance/testdata/workflow/run-delete.txtar diff --git a/acceptance/testdata/workflow/run-delete.txtar b/acceptance/testdata/workflow/run-delete.txtar new file mode 100644 index 000000000..16dc224fb --- /dev/null +++ b/acceptance/testdata/workflow/run-delete.txtar @@ -0,0 +1,74 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to watch & delete +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +# Delete the workflow run +exec gh run delete $RUN_ID +stdout '✓ Request to delete workflow submitted.' + +# It takes some time for a workflow run to be deleted +sleep 5 + +# Check the workflow run is cancelled +exec gh run list +stdout '' + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! From 3d3e061d06b6384efdc6189aad649b3acca00d35 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:19:47 -0600 Subject: [PATCH 07/17] Create run-download.txtar --- .../testdata/workflow/run-download.txtar | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 acceptance/testdata/workflow/run-download.txtar diff --git a/acceptance/testdata/workflow/run-download.txtar b/acceptance/testdata/workflow/run-download.txtar new file mode 100644 index 000000000..2aa3cae64 --- /dev/null +++ b/acceptance/testdata/workflow/run-download.txtar @@ -0,0 +1,72 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to watch +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +# Download the artifact +exec gh run download $RUN_ID +stdout '' + +# Check if we downloaded the artifact +exists ./my-artifact/world.txt + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + - run: mkdir -p path/to/artifact + - run: echo hello > world.txt + - uses: actions/upload-artifact@v4 + with: + name: my-artifact + path: world.txt \ No newline at end of file From 745863b3656a5f106dffcc11f9e5835fe7851362 Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:19:49 -0600 Subject: [PATCH 08/17] Create run-rerun.txtar --- acceptance/testdata/workflow/run-rerun.txtar | 79 ++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 acceptance/testdata/workflow/run-rerun.txtar diff --git a/acceptance/testdata/workflow/run-rerun.txtar b/acceptance/testdata/workflow/run-rerun.txtar new file mode 100644 index 000000000..e5b895454 --- /dev/null +++ b/acceptance/testdata/workflow/run-rerun.txtar @@ -0,0 +1,79 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to rerun +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +# Get the run ID we want to rerun +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Rerun the workflow run +# There's some inconsistency here compared to `run delete` and other `run` +# commands because run rerun doesn't return output in non-tty. +exec gh run rerun $RUN_ID +stdout '' + +# It takes some time for a workflow run to register +sleep 5 + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + + # Runs a single command using the runners shell + - name: Run a one-line script + run: echo Hello, world! From 682b75fb4e91bc90da966d74543acb1f36fcfb8d Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:19:52 -0600 Subject: [PATCH 09/17] Create run-view.txtar --- acceptance/testdata/workflow/run-view.txtar | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 acceptance/testdata/workflow/run-view.txtar diff --git a/acceptance/testdata/workflow/run-view.txtar b/acceptance/testdata/workflow/run-view.txtar new file mode 100644 index 000000000..c3ace4c4f --- /dev/null +++ b/acceptance/testdata/workflow/run-view.txtar @@ -0,0 +1,66 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to view +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +# View the workflow run +exec gh run view $RUN_ID + +-- workflow.yml -- +# This is a basic workflow to help you get started with Actions + +name: Test Workflow Name + +# Controls when the workflow will run +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + + # Runs a single command using the runners shell + - name: Run a one-line script + run: sleep 10 From 924d81a34bed6f34fbbe134a1f2f5b644fe0715b Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:59:19 -0600 Subject: [PATCH 10/17] Create cache-list-delete.txtar --- .../testdata/workflow/cache-list-delete.txtar | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 acceptance/testdata/workflow/cache-list-delete.txtar diff --git a/acceptance/testdata/workflow/cache-list-delete.txtar b/acceptance/testdata/workflow/cache-list-delete.txtar new file mode 100644 index 000000000..30ce78bd0 --- /dev/null +++ b/acceptance/testdata/workflow/cache-list-delete.txtar @@ -0,0 +1,70 @@ +# Use gh as a credential helper +exec gh auth setup-git + +# Create a repository with a file so it has a default branch +exec gh repo create $ORG/$SCRIPT_NAME-$RANDOM_STRING --add-readme --private + +# Defer repo cleanup +defer gh repo delete --yes $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# Clone the repo +exec gh repo clone $ORG/$SCRIPT_NAME-$RANDOM_STRING + +# commit the workflow file +cd $SCRIPT_NAME-$RANDOM_STRING +mkdir .github/workflows +mv ../workflow.yml .github/workflows/workflow.yml +exec git add .github/workflows/workflow.yml +exec git commit -m 'Create workflow file' +exec git push -u origin main + +# Sleep because it takes a second for the workflow to register +sleep 1 + +# Check the workflow is indeed created +exec gh workflow list +stdout 'Test Workflow Name' + +# Run the workflow +exec gh workflow run 'Test Workflow Name' + +# It takes some time for a workflow run to register +sleep 5 + +# Get the run ID we want to watch +exec gh run list --json databaseId --jq '.[0].databaseId' +stdout2env RUN_ID + +# Wait for workflow to complete +exec gh run watch $RUN_ID --exit-status + +# List the cache +exec gh cache list +stdout 'Linux-values' + +# Delete the cache +exec gh cache delete 'Linux-values' +stdout '' + +-- workflow.yml -- +name: Test Workflow Name + +on: workflow_dispatch + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Cache values + id: cache-values + uses: actions/cache@v4 + with: + path: values.txt + key: ${{ runner.os }}-values + + - name: Generate values file + if: steps.cache-values.outputs.cache-hit != 'true' + run: echo "values" > values.txt \ No newline at end of file From 8d626312a487c5f7efa9acc4cf708c9200c967de Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:59:21 -0600 Subject: [PATCH 11/17] Update run-rerun.txtar --- acceptance/testdata/workflow/run-rerun.txtar | 2 -- 1 file changed, 2 deletions(-) diff --git a/acceptance/testdata/workflow/run-rerun.txtar b/acceptance/testdata/workflow/run-rerun.txtar index e5b895454..1448dec4b 100644 --- a/acceptance/testdata/workflow/run-rerun.txtar +++ b/acceptance/testdata/workflow/run-rerun.txtar @@ -43,8 +43,6 @@ exec gh run list --json databaseId --jq '.[0].databaseId' stdout2env RUN_ID # Rerun the workflow run -# There's some inconsistency here compared to `run delete` and other `run` -# commands because run rerun doesn't return output in non-tty. exec gh run rerun $RUN_ID stdout '' From 4ce82361422807f0a3f066f93b89ddfeb11dba0c Mon Sep 17 00:00:00 2001 From: bagtoad <47394200+BagToad@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:09:47 -0600 Subject: [PATCH 12/17] sleep 10s before checking for workflow run --- acceptance/testdata/workflow/cache-list-delete.txtar | 2 +- acceptance/testdata/workflow/run-cancel.txtar | 2 +- acceptance/testdata/workflow/run-delete.txtar | 2 +- acceptance/testdata/workflow/run-download.txtar | 2 +- acceptance/testdata/workflow/run-rerun.txtar | 8 ++------ acceptance/testdata/workflow/run-view.txtar | 2 +- acceptance/testdata/workflow/workflow-run.txtar | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) diff --git a/acceptance/testdata/workflow/cache-list-delete.txtar b/acceptance/testdata/workflow/cache-list-delete.txtar index 30ce78bd0..aa1dc91a7 100644 --- a/acceptance/testdata/workflow/cache-list-delete.txtar +++ b/acceptance/testdata/workflow/cache-list-delete.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to watch exec gh run list --json databaseId --jq '.[0].databaseId' diff --git a/acceptance/testdata/workflow/run-cancel.txtar b/acceptance/testdata/workflow/run-cancel.txtar index f06912c90..2f1170bbc 100644 --- a/acceptance/testdata/workflow/run-cancel.txtar +++ b/acceptance/testdata/workflow/run-cancel.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to cancel exec gh run list --json databaseId --jq '.[0].databaseId' diff --git a/acceptance/testdata/workflow/run-delete.txtar b/acceptance/testdata/workflow/run-delete.txtar index 16dc224fb..45b11f2d1 100644 --- a/acceptance/testdata/workflow/run-delete.txtar +++ b/acceptance/testdata/workflow/run-delete.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to watch & delete exec gh run list --json databaseId --jq '.[0].databaseId' diff --git a/acceptance/testdata/workflow/run-download.txtar b/acceptance/testdata/workflow/run-download.txtar index 2aa3cae64..a8faaacec 100644 --- a/acceptance/testdata/workflow/run-download.txtar +++ b/acceptance/testdata/workflow/run-download.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to watch exec gh run list --json databaseId --jq '.[0].databaseId' diff --git a/acceptance/testdata/workflow/run-rerun.txtar b/acceptance/testdata/workflow/run-rerun.txtar index 1448dec4b..273a4adea 100644 --- a/acceptance/testdata/workflow/run-rerun.txtar +++ b/acceptance/testdata/workflow/run-rerun.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to rerun exec gh run list --json databaseId --jq '.[0].databaseId' @@ -38,16 +38,12 @@ stdout2env RUN_ID # Wait for workflow to complete exec gh run watch $RUN_ID --exit-status -# Get the run ID we want to rerun -exec gh run list --json databaseId --jq '.[0].databaseId' -stdout2env RUN_ID - # Rerun the workflow run exec gh run rerun $RUN_ID stdout '' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Wait for workflow to complete exec gh run watch $RUN_ID --exit-status diff --git a/acceptance/testdata/workflow/run-view.txtar b/acceptance/testdata/workflow/run-view.txtar index c3ace4c4f..bc739e580 100644 --- a/acceptance/testdata/workflow/run-view.txtar +++ b/acceptance/testdata/workflow/run-view.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Get the run ID we want to view exec gh run list --json databaseId --jq '.[0].databaseId' diff --git a/acceptance/testdata/workflow/workflow-run.txtar b/acceptance/testdata/workflow/workflow-run.txtar index 7e9a823ee..010189c01 100644 --- a/acceptance/testdata/workflow/workflow-run.txtar +++ b/acceptance/testdata/workflow/workflow-run.txtar @@ -29,7 +29,7 @@ stdout 'Test Workflow Name' exec gh workflow run 'Test Workflow Name' # It takes some time for a workflow run to register -sleep 5 +sleep 10 # Check the workflow run exists exec gh run list From 8f567e2791abe3cf6bc750b383753184ad527a16 Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 17 Oct 2024 14:13:50 +0200 Subject: [PATCH 13/17] Watch for run to end for cancel Acceptance test --- acceptance/testdata/workflow/run-cancel.txtar | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance/testdata/workflow/run-cancel.txtar b/acceptance/testdata/workflow/run-cancel.txtar index 2f1170bbc..08d8d519a 100644 --- a/acceptance/testdata/workflow/run-cancel.txtar +++ b/acceptance/testdata/workflow/run-cancel.txtar @@ -39,8 +39,8 @@ stdout2env RUN_ID exec gh run cancel $RUN_ID stdout '✓ Request to cancel workflow [0-9]+ submitted.' -# It takes some time for a workflow run to be cancelled -sleep 5 +# Wait for workflow to complete +exec gh run watch $RUN_ID # Check the workflow run is cancelled exec gh run list --json conclusion --jq '.[0].conclusion' From 93081c9e65acaf6c56009a642a03259d48a34a91 Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 17 Oct 2024 14:25:02 +0200 Subject: [PATCH 14/17] Use regex assert for enable disable workflow Acceptance test --- acceptance/testdata/workflow/workflow-enable-disable.txtar | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/acceptance/testdata/workflow/workflow-enable-disable.txtar b/acceptance/testdata/workflow/workflow-enable-disable.txtar index c248c1cad..c18ae7dc7 100644 --- a/acceptance/testdata/workflow/workflow-enable-disable.txtar +++ b/acceptance/testdata/workflow/workflow-enable-disable.txtar @@ -28,11 +28,6 @@ stdout 'Test Workflow Name' # disable the workflow exec gh workflow disable 'Test Workflow Name' -# Check the workflow is indeed disabled -# Disabled workflows are hidden by default. -exec gh workflow list -stdout '' - # Check that the listing shows it is disabled exec gh workflow list --all stdout 'Test\s+Workflow\s+Name\s+disabled_manually\s+\d+' @@ -42,7 +37,7 @@ exec gh workflow enable 'Test Workflow Name' # Check the workflow is indeed enabled exec gh workflow list -stdout 'Test Workflow Name' +stdout 'Test\s+Workflow\s+Name\s+active\s+\d+' -- workflow.yml -- # This is a basic workflow to help you get started with Actions From 0f62ec20e261796d314586e45446ee2736ac200c Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 17 Oct 2024 15:06:45 +0200 Subject: [PATCH 15/17] Adjust sleeps to echos in Acceptance workflows --- acceptance/testdata/workflow/run-view.txtar | 2 +- acceptance/testdata/workflow/workflow-enable-disable.txtar | 2 +- acceptance/testdata/workflow/workflow-list.txtar | 2 +- acceptance/testdata/workflow/workflow-view.txtar | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/acceptance/testdata/workflow/run-view.txtar b/acceptance/testdata/workflow/run-view.txtar index bc739e580..25f12c3a5 100644 --- a/acceptance/testdata/workflow/run-view.txtar +++ b/acceptance/testdata/workflow/run-view.txtar @@ -63,4 +63,4 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: sleep 10 + run: echo Hello, world! diff --git a/acceptance/testdata/workflow/workflow-enable-disable.txtar b/acceptance/testdata/workflow/workflow-enable-disable.txtar index c18ae7dc7..f0b58116f 100644 --- a/acceptance/testdata/workflow/workflow-enable-disable.txtar +++ b/acceptance/testdata/workflow/workflow-enable-disable.txtar @@ -63,4 +63,4 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: sleep 10 + run: echo Hello, world! diff --git a/acceptance/testdata/workflow/workflow-list.txtar b/acceptance/testdata/workflow/workflow-list.txtar index 8cd211de0..ad0d87c88 100644 --- a/acceptance/testdata/workflow/workflow-list.txtar +++ b/acceptance/testdata/workflow/workflow-list.txtar @@ -49,4 +49,4 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: sleep 10 + run: echo Hello, world! diff --git a/acceptance/testdata/workflow/workflow-view.txtar b/acceptance/testdata/workflow/workflow-view.txtar index 0783e7fac..d3bc3d252 100644 --- a/acceptance/testdata/workflow/workflow-view.txtar +++ b/acceptance/testdata/workflow/workflow-view.txtar @@ -49,4 +49,4 @@ jobs: # Runs a single command using the runners shell - name: Run a one-line script - run: sleep 10 + run: echo Hello, world! From 07ea43ae5ab6b987ad0123b8d7f53553e1addc3f Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 17 Oct 2024 15:09:27 +0200 Subject: [PATCH 16/17] Remove empty stdout checks --- acceptance/testdata/workflow/cache-list-delete.txtar | 3 +-- acceptance/testdata/workflow/run-delete.txtar | 2 +- acceptance/testdata/workflow/run-download.txtar | 3 +-- acceptance/testdata/workflow/run-rerun.txtar | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/acceptance/testdata/workflow/cache-list-delete.txtar b/acceptance/testdata/workflow/cache-list-delete.txtar index aa1dc91a7..6a99f4bc2 100644 --- a/acceptance/testdata/workflow/cache-list-delete.txtar +++ b/acceptance/testdata/workflow/cache-list-delete.txtar @@ -44,7 +44,6 @@ stdout 'Linux-values' # Delete the cache exec gh cache delete 'Linux-values' -stdout '' -- workflow.yml -- name: Test Workflow Name @@ -67,4 +66,4 @@ jobs: - name: Generate values file if: steps.cache-values.outputs.cache-hit != 'true' - run: echo "values" > values.txt \ No newline at end of file + run: echo "values" > values.txt diff --git a/acceptance/testdata/workflow/run-delete.txtar b/acceptance/testdata/workflow/run-delete.txtar index 45b11f2d1..72d098740 100644 --- a/acceptance/testdata/workflow/run-delete.txtar +++ b/acceptance/testdata/workflow/run-delete.txtar @@ -45,7 +45,7 @@ stdout '✓ Request to delete workflow submitted.' # It takes some time for a workflow run to be deleted sleep 5 -# Check the workflow run is cancelled +# Check the workflow run is cancelled, which is implied by an empty list exec gh run list stdout '' diff --git a/acceptance/testdata/workflow/run-download.txtar b/acceptance/testdata/workflow/run-download.txtar index a8faaacec..dc0446598 100644 --- a/acceptance/testdata/workflow/run-download.txtar +++ b/acceptance/testdata/workflow/run-download.txtar @@ -40,7 +40,6 @@ exec gh run watch $RUN_ID --exit-status # Download the artifact exec gh run download $RUN_ID -stdout '' # Check if we downloaded the artifact exists ./my-artifact/world.txt @@ -69,4 +68,4 @@ jobs: - uses: actions/upload-artifact@v4 with: name: my-artifact - path: world.txt \ No newline at end of file + path: world.txt diff --git a/acceptance/testdata/workflow/run-rerun.txtar b/acceptance/testdata/workflow/run-rerun.txtar index 273a4adea..446aabbc4 100644 --- a/acceptance/testdata/workflow/run-rerun.txtar +++ b/acceptance/testdata/workflow/run-rerun.txtar @@ -40,7 +40,6 @@ exec gh run watch $RUN_ID --exit-status # Rerun the workflow run exec gh run rerun $RUN_ID -stdout '' # It takes some time for a workflow run to register sleep 10 From dc3e805078d6c043a2bccff29a8b3aca8ebc507e Mon Sep 17 00:00:00 2001 From: William Martin Date: Thu, 17 Oct 2024 15:11:45 +0200 Subject: [PATCH 17/17] Remove unnecesary mkdir from download Acceptance test --- acceptance/testdata/workflow/run-download.txtar | 1 - 1 file changed, 1 deletion(-) diff --git a/acceptance/testdata/workflow/run-download.txtar b/acceptance/testdata/workflow/run-download.txtar index dc0446598..653fdbef5 100644 --- a/acceptance/testdata/workflow/run-download.txtar +++ b/acceptance/testdata/workflow/run-download.txtar @@ -63,7 +63,6 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: - - run: mkdir -p path/to/artifact - run: echo hello > world.txt - uses: actions/upload-artifact@v4 with: