-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Add acceptance tests for workflow, run, and cache commands
#9766
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
williammartin
merged 17 commits into
trunk
from
kw/github-cli-585-add-acceptance-tests-for-actions-commands
Oct 17, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c3ffdc9
implement base workflow list acceptance test
BagToad 5f919bc
implement workflow enable/disable acceptance test
BagToad 0b1d692
Create workflow-view.txtar
BagToad 3737f10
Create workflow-run.txtar
BagToad 446ffed
Create run-cancel.txtar
BagToad 3f080e0
Create run-delete.txtar
BagToad 3d3e061
Create run-download.txtar
BagToad 745863b
Create run-rerun.txtar
BagToad 682b75f
Create run-view.txtar
BagToad 924d81a
Create cache-list-delete.txtar
BagToad 8d62631
Update run-rerun.txtar
BagToad 4ce8236
sleep 10s before checking for workflow run
BagToad 8f567e2
Watch for run to end for cancel Acceptance test
williammartin 93081c9
Use regex assert for enable disable workflow Acceptance test
williammartin 0f62ec2
Adjust sleeps to echos in Acceptance workflows
williammartin 07ea43a
Remove empty stdout checks
williammartin dc3e805
Remove unnecesary mkdir from download Acceptance test
williammartin 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
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,69 @@ | ||
| # 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 10 | ||
|
|
||
| # 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' | ||
|
|
||
| -- 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 |
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,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 10 | ||
|
|
||
| # 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.' | ||
|
|
||
| # 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' | ||
| 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 |
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,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 10 | ||
|
|
||
| # 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, which is implied by an empty list | ||
| 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! |
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 @@ | ||
| # 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 10 | ||
|
|
||
| # 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 | ||
|
|
||
| # 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: echo hello > world.txt | ||
| - uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: my-artifact | ||
| path: world.txt |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While reviewing this, @BagToad and I noodled on some ideas to avoid flakes around sleeping for arbitrary amounts of time. Both approaches required a new command. One would be a
eventuallyexecsingle command which would re-exec a command repeatedly until the exit code was0. Then we could usejqto hackily cause an error based on some state e.g.:A perhaps better approach we spiked in f98f45f
Which allows for retryable stdout assertions like so: