|
| 1 | +name: Check Poetry |
| 2 | + |
| 3 | +on: |
| 4 | + create: |
| 5 | + push: |
| 6 | + paths: |
| 7 | + - ".github/workflows/check-poetry-task.ya?ml" |
| 8 | + - "**/poetry.lock" |
| 9 | + - "**/pyproject.toml" |
| 10 | + - "Taskfile.ya?ml" |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - ".github/workflows/check-poetry-task.ya?ml" |
| 14 | + - "**/poetry.lock" |
| 15 | + - "**/pyproject.toml" |
| 16 | + - "Taskfile.ya?ml" |
| 17 | + schedule: |
| 18 | + # Run periodically to catch breakage caused by external changes. |
| 19 | + - cron: "0 11 * * THU" |
| 20 | + workflow_dispatch: |
| 21 | + repository_dispatch: |
| 22 | + |
| 23 | +jobs: |
| 24 | + run-determination: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: {} |
| 27 | + outputs: |
| 28 | + result: ${{ steps.determination.outputs.result }} |
| 29 | + steps: |
| 30 | + - name: Determine if the rest of the workflow should run |
| 31 | + id: determination |
| 32 | + run: | |
| 33 | + RELEASE_BRANCH_REGEX="^refs/heads/v[0-9]+$" |
| 34 | + # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead. |
| 35 | + if [[ |
| 36 | + "${{ github.event_name }}" != "create" || |
| 37 | + "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX |
| 38 | + ]]; then |
| 39 | + # Run the other jobs. |
| 40 | + RESULT="true" |
| 41 | + else |
| 42 | + # There is no need to run the other jobs. |
| 43 | + RESULT="false" |
| 44 | + fi |
| 45 | +
|
| 46 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + validate: |
| 49 | + needs: run-determination |
| 50 | + if: needs.run-determination.outputs.result == 'true' |
| 51 | + runs-on: ubuntu-latest |
| 52 | + permissions: |
| 53 | + contents: read |
| 54 | + |
| 55 | + steps: |
| 56 | + - name: Checkout repository |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Install Python |
| 60 | + uses: actions/setup-python@v5 |
| 61 | + with: |
| 62 | + python-version-file: pyproject.toml |
| 63 | + |
| 64 | + - name: Install Task |
| 65 | + uses: arduino/setup-task@v2 |
| 66 | + with: |
| 67 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + version: 3.x |
| 69 | + |
| 70 | + - name: Validate pyproject.toml |
| 71 | + run: | |
| 72 | + task \ |
| 73 | + --silent \ |
| 74 | + poetry:validate |
| 75 | +
|
| 76 | + check-sync: |
| 77 | + needs: run-determination |
| 78 | + if: needs.run-determination.outputs.result == 'true' |
| 79 | + runs-on: ubuntu-latest |
| 80 | + permissions: |
| 81 | + contents: read |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Checkout repository |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: Install Python |
| 88 | + uses: actions/setup-python@v5 |
| 89 | + with: |
| 90 | + python-version-file: pyproject.toml |
| 91 | + |
| 92 | + - name: Install Task |
| 93 | + uses: arduino/setup-task@v2 |
| 94 | + with: |
| 95 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + version: 3.x |
| 97 | + |
| 98 | + - name: Sync lockfile |
| 99 | + run: | |
| 100 | + task \ |
| 101 | + --silent \ |
| 102 | + poetry:sync |
| 103 | +
|
| 104 | + - name: Check if lockfile was out of sync |
| 105 | + run: | |
| 106 | + git diff \ |
| 107 | + --color \ |
| 108 | + --exit-code \ |
| 109 | + poetry.lock |
0 commit comments