|
| 1 | +name: Internal - Tests for working-directory action |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + tests: |
| 11 | + name: Tests for working-directory action |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Arrange - Checkout repository |
| 15 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 16 | + with: |
| 17 | + persist-credentials: false |
| 18 | + |
| 19 | + - name: Act - Resolve workspace root directory |
| 20 | + id: working-directory |
| 21 | + uses: ./actions/working-directory |
| 22 | + with: |
| 23 | + working-directory: . |
| 24 | + |
| 25 | + - name: Assert - Check workspace root outputs |
| 26 | + run: | |
| 27 | + if [ "${STEPS_WORKING_DIRECTORY_OUTPUTS_ABSOLUTE_PATH}" != "${GITHUB_WORKSPACE}" ]; then |
| 28 | + echo "working-directory absolute-path output is not valid" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + if [ "${STEPS_WORKING_DIRECTORY_OUTPUTS_WORKSPACE_RELATIVE_PATH}" != "." ]; then |
| 33 | + echo "working-directory workspace-relative-path output is not valid" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + env: |
| 37 | + STEPS_WORKING_DIRECTORY_OUTPUTS_ABSOLUTE_PATH: ${{ steps.working-directory.outputs.absolute-path }} |
| 38 | + STEPS_WORKING_DIRECTORY_OUTPUTS_WORKSPACE_RELATIVE_PATH: ${{ steps.working-directory.outputs.workspace-relative-path }} |
| 39 | + |
| 40 | + - name: Act - Run outside-workspace path with enforcement enabled |
| 41 | + id: outside-workspace-disallowed |
| 42 | + continue-on-error: true |
| 43 | + uses: ./actions/working-directory |
| 44 | + with: |
| 45 | + working-directory: /tmp |
| 46 | + enforce-path-in-workspace: true |
| 47 | + |
| 48 | + - name: Assert - Check enforcement failure outside workspace |
| 49 | + run: | |
| 50 | + if [ "${STEPS_OUTSIDE_WORKSPACE_DISALLOWED_OUTCOME}" != "failure" ]; then |
| 51 | + echo "working-directory should fail when path is outside workspace and enforcement is enabled" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + env: |
| 55 | + STEPS_OUTSIDE_WORKSPACE_DISALLOWED_OUTCOME: ${{ steps.outside-workspace-disallowed.outcome }} |
| 56 | + |
| 57 | + - name: Act - Run outside-workspace path with enforcement disabled |
| 58 | + id: outside-workspace-allowed |
| 59 | + uses: ./actions/working-directory |
| 60 | + with: |
| 61 | + working-directory: /tmp |
| 62 | + enforce-path-in-workspace: false |
| 63 | + |
| 64 | + - name: Assert - Check enforcement opt-out outside workspace |
| 65 | + run: | |
| 66 | + if [ "${STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_ABSOLUTE_PATH}" != "/tmp" ]; then |
| 67 | + echo "working-directory absolute-path output is not valid when enforcement is disabled" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | +
|
| 71 | + if [[ "${STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_WORKSPACE_RELATIVE_PATH}" != ..* ]]; then |
| 72 | + echo "working-directory workspace-relative-path should be outside workspace when enforcement is disabled" |
| 73 | + exit 1 |
| 74 | + fi |
| 75 | + env: |
| 76 | + STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_ABSOLUTE_PATH: ${{ steps.outside-workspace-allowed.outputs.absolute-path }} |
| 77 | + STEPS_OUTSIDE_WORKSPACE_ALLOWED_OUTPUTS_WORKSPACE_RELATIVE_PATH: ${{ steps.outside-workspace-allowed.outputs.workspace-relative-path }} |
0 commit comments