From 3be05f941f6d22cdcd5b859d12efed83b8d38a15 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 3 Jan 2025 12:42:31 +0530 Subject: [PATCH 1/7] refactor: update GitHub Actions workflow for fixture regeneration - Renamed job from `trigger_pipeline` to `regenerate_fixtures`. - Simplified the workflow by using an external action for fixture regeneration. - Removed redundant steps related to checkout, Go setup, and fixture update. - Inherited secrets for better security management. --- .github/workflows/fixtures.yml | 47 +++++----------------------------- 1 file changed, 7 insertions(+), 40 deletions(-) diff --git a/.github/workflows/fixtures.yml b/.github/workflows/fixtures.yml index efcc5144..602b353d 100644 --- a/.github/workflows/fixtures.yml +++ b/.github/workflows/fixtures.yml @@ -1,49 +1,16 @@ name: Trigger Fixture Regeneration +permissions: + contents: write + pull-requests: write + on: pull_request: types: - labeled -permissions: - contents: write - pull-requests: write - jobs: - trigger_pipeline: + regenerate_fixtures: if: github.event.label.name == 'regenerate-fixtures' - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - token: ${{ secrets.RYAN_FIXTURE_GEN_PAT }} - - - name: Set up Go - uses: actions/setup-go@v1 - with: - go-version: 1.22.x - - - uses: actions-ecosystem/action-create-comment@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - body: | - Triggered a [Github Actions](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) job to update fixtures. - - - uses: actions-ecosystem/action-remove-labels@v1 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - labels: regenerate-fixtures - - - name: Regenerate Fixtures - run: CODECRAFTERS_RECORD_FIXTURES=true make test - - - name: Update Fixtures - run: | - git config --global user.email "ryan-gg@outlook.com" - git config --global user.name "Ryan Gang" - git remote set-url origin https://ryan-gang:${{ secrets.RYAN_FIXTURE_GEN_PAT }}@github.com/codecrafters-io/shell-tester.git - git fetch origin ${{ github.head_ref }} - git checkout ${{ github.head_ref }} - git diff --quiet || (git add . && git commit -m "ci: add regenerated fixtures" && git push) + uses: codecrafters-io/tester-utils/.github/workflows/fixtures.yml@fixture-gen-action + secrets: inherit \ No newline at end of file From f4f9e617f5c4abeac75f11e5736ebd251a88ee21 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 22:29:06 +0530 Subject: [PATCH 2/7] chore: update GitHub Actions workflow to specify tester repository for fixture regeneration --- .github/workflows/fixtures.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/fixtures.yml b/.github/workflows/fixtures.yml index 602b353d..26dd4c99 100644 --- a/.github/workflows/fixtures.yml +++ b/.github/workflows/fixtures.yml @@ -13,4 +13,6 @@ jobs: regenerate_fixtures: if: github.event.label.name == 'regenerate-fixtures' uses: codecrafters-io/tester-utils/.github/workflows/fixtures.yml@fixture-gen-action + with: + tester_repo: shell-tester secrets: inherit \ No newline at end of file From 7916a687b453726ceec28ad749950ec34b44071d Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 22:32:07 +0530 Subject: [PATCH 3/7] test: trigger CI fixture run --- internal/stage2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/stage2.go b/internal/stage2.go index 7ed3d5c8..8f41eece 100644 --- a/internal/stage2.go +++ b/internal/stage2.go @@ -17,7 +17,7 @@ func testInvalidCommand(stageHarness *test_case_harness.TestCaseHarness) error { } testCase := test_cases.InvalidCommandTestCase{ - Command: getRandomInvalidCommand(), + Command: "invalid", } if err := testCase.RunWithoutNextPromptAssertion(asserter, shell, logger); err != nil { return err From 9fef76ef48214f56efc8cea28fef795fad83e57b Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 17:30:34 +0000 Subject: [PATCH 4/7] ci: add regenerated fixtures --- internal/test_helpers/fixtures/base/pass | 4 ++-- internal/test_helpers/fixtures/escape_codes | 4 ++-- internal/test_helpers/fixtures/navigation/pass | 6 +++--- internal/test_helpers/fixtures/no_output | 4 ++-- internal/test_helpers/fixtures/wrong_output | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/test_helpers/fixtures/base/pass b/internal/test_helpers/fixtures/base/pass index a46012fc..f3fe8bc8 100644 --- a/internal/test_helpers/fixtures/base/pass +++ b/internal/test_helpers/fixtures/base/pass @@ -89,8 +89,8 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid_banana_command -[your-program] bash: invalid_banana_command: command not found +[your-program] $ invalid +[your-program] bash: invalid: command not found [stage-2] ✓ Received command not found message [your-program] $ [stage-2] Test passed. diff --git a/internal/test_helpers/fixtures/escape_codes b/internal/test_helpers/fixtures/escape_codes index 6dee714b..91842509 100644 --- a/internal/test_helpers/fixtures/escape_codes +++ b/internal/test_helpers/fixtures/escape_codes @@ -2,8 +2,8 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid_pear_command -[your-program] invalid_pear_command: command not found +[your-program] $ invalid +[your-program] invalid: command not found [stage-2] ✓ Received command not found message [your-program] $ [stage-2] Test passed. diff --git a/internal/test_helpers/fixtures/navigation/pass b/internal/test_helpers/fixtures/navigation/pass index 162b88fe..a3524bb1 100644 --- a/internal/test_helpers/fixtures/navigation/pass +++ b/internal/test_helpers/fixtures/navigation/pass @@ -48,7 +48,7 @@ Debug = true [your-program] pwd is a shell builtin [stage-9] ✓ Received expected response [your-program] $ pwd -[your-program] /workspaces/shell-tester/internal +[your-program] /home/runner/work/shell-tester/shell-tester/internal [stage-9] ✓ Received current working directory response [your-program] $ [stage-9] Test passed. @@ -148,8 +148,8 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid_apple_command -[your-program] bash: invalid_apple_command: command not found +[your-program] $ invalid +[your-program] bash: invalid: command not found [stage-2] ✓ Received command not found message [your-program] $ [stage-2] Test passed. diff --git a/internal/test_helpers/fixtures/no_output b/internal/test_helpers/fixtures/no_output index cecfa7ba..51383fe0 100644 --- a/internal/test_helpers/fixtures/no_output +++ b/internal/test_helpers/fixtures/no_output @@ -2,9 +2,9 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid_pear_command +[your-program] $ invalid [stage-2] Output does not match expected value. -[stage-2] Expected: "invalid_pear_command: command not found" +[stage-2] Expected: "invalid: command not found" [stage-2] Received: "" [stage-2] Assertion failed. [stage-2] Test failed diff --git a/internal/test_helpers/fixtures/wrong_output b/internal/test_helpers/fixtures/wrong_output index 63dd8389..323028fd 100644 --- a/internal/test_helpers/fixtures/wrong_output +++ b/internal/test_helpers/fixtures/wrong_output @@ -2,10 +2,10 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid_pear_command -[your-program] Command: invalid_pear_command +[your-program] $ invalid +[your-program] Command: invalid [stage-2] Output does not match expected value. -[stage-2] Expected: "invalid_pear_command: command not found" -[stage-2] Received: "Command: invalid_pear_command" +[stage-2] Expected: "invalid: command not found" +[stage-2] Received: "Command: invalid" [stage-2] Assertion failed. [stage-2] Test failed From 47ce9d6e6e284948b508f8a9446340d6c08aecfb Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 23:03:35 +0530 Subject: [PATCH 5/7] revert: change to stage2 for ci test --- internal/stage2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/stage2.go b/internal/stage2.go index 8f41eece..7ed3d5c8 100644 --- a/internal/stage2.go +++ b/internal/stage2.go @@ -17,7 +17,7 @@ func testInvalidCommand(stageHarness *test_case_harness.TestCaseHarness) error { } testCase := test_cases.InvalidCommandTestCase{ - Command: "invalid", + Command: getRandomInvalidCommand(), } if err := testCase.RunWithoutNextPromptAssertion(asserter, shell, logger); err != nil { return err From dafdf08a8885d0bfdcc9a7dcffa44e7e38247f87 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 17:45:58 +0000 Subject: [PATCH 6/7] ci: add regenerated fixtures --- internal/test_helpers/fixtures/escape_codes | 4 ++-- internal/test_helpers/fixtures/navigation/pass | 4 ++-- internal/test_helpers/fixtures/no_output | 4 ++-- internal/test_helpers/fixtures/wrong_output | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/test_helpers/fixtures/escape_codes b/internal/test_helpers/fixtures/escape_codes index 91842509..6dee714b 100644 --- a/internal/test_helpers/fixtures/escape_codes +++ b/internal/test_helpers/fixtures/escape_codes @@ -2,8 +2,8 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid -[your-program] invalid: command not found +[your-program] $ invalid_pear_command +[your-program] invalid_pear_command: command not found [stage-2] ✓ Received command not found message [your-program] $ [stage-2] Test passed. diff --git a/internal/test_helpers/fixtures/navigation/pass b/internal/test_helpers/fixtures/navigation/pass index 8f69b69e..9617bcee 100644 --- a/internal/test_helpers/fixtures/navigation/pass +++ b/internal/test_helpers/fixtures/navigation/pass @@ -148,8 +148,8 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid -[your-program] bash: invalid: command not found +[your-program] $ invalid_strawberry_command +[your-program] bash: invalid_strawberry_command: command not found [stage-2] ✓ Received command not found message [your-program] $ [stage-2] Test passed. diff --git a/internal/test_helpers/fixtures/no_output b/internal/test_helpers/fixtures/no_output index 51383fe0..cecfa7ba 100644 --- a/internal/test_helpers/fixtures/no_output +++ b/internal/test_helpers/fixtures/no_output @@ -2,9 +2,9 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid +[your-program] $ invalid_pear_command [stage-2] Output does not match expected value. -[stage-2] Expected: "invalid: command not found" +[stage-2] Expected: "invalid_pear_command: command not found" [stage-2] Received: "" [stage-2] Assertion failed. [stage-2] Test failed diff --git a/internal/test_helpers/fixtures/wrong_output b/internal/test_helpers/fixtures/wrong_output index 323028fd..63dd8389 100644 --- a/internal/test_helpers/fixtures/wrong_output +++ b/internal/test_helpers/fixtures/wrong_output @@ -2,10 +2,10 @@ Debug = true [stage-2] Running tests for Stage #2: cz2 [stage-2] Running ./your_shell.sh -[your-program] $ invalid -[your-program] Command: invalid +[your-program] $ invalid_pear_command +[your-program] Command: invalid_pear_command [stage-2] Output does not match expected value. -[stage-2] Expected: "invalid: command not found" -[stage-2] Received: "Command: invalid" +[stage-2] Expected: "invalid_pear_command: command not found" +[stage-2] Received: "Command: invalid_pear_command" [stage-2] Assertion failed. [stage-2] Test failed From 2ede3ae64cc5ea21e872df16c1fe8d66d3ac6ddc Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 7 Jan 2025 23:22:24 +0530 Subject: [PATCH 7/7] chore: update GitHub Actions workflow to use the latest fixture generation action --- .github/workflows/fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/fixtures.yml b/.github/workflows/fixtures.yml index 26dd4c99..421a2a82 100644 --- a/.github/workflows/fixtures.yml +++ b/.github/workflows/fixtures.yml @@ -12,7 +12,7 @@ on: jobs: regenerate_fixtures: if: github.event.label.name == 'regenerate-fixtures' - uses: codecrafters-io/tester-utils/.github/workflows/fixtures.yml@fixture-gen-action + uses: codecrafters-io/tester-utils/.github/workflows/fixtures.yml@master with: tester_repo: shell-tester secrets: inherit \ No newline at end of file