|
| 1 | +name: Check Category Order Metadata |
| 2 | + |
| 3 | +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows |
| 4 | +on: |
| 5 | + create: |
| 6 | + push: |
| 7 | + paths: |
| 8 | + - ".github/workflows/check-order-metadata-task.ya?ml" |
| 9 | + - "poetry.lock" |
| 10 | + - "pyproject.toml" |
| 11 | + - "Taskfile.ya?ml" |
| 12 | + - "assets/generate-category-order-metadata/*" |
| 13 | + - "content/categories/order.md" |
| 14 | + pull_request: |
| 15 | + paths: |
| 16 | + - ".github/workflows/check-order-metadata-task.ya?ml" |
| 17 | + - "poetry.lock" |
| 18 | + - "pyproject.toml" |
| 19 | + - "Taskfile.ya?ml" |
| 20 | + - "assets/generate-category-order-metadata/*" |
| 21 | + - "content/categories/order.md" |
| 22 | + schedule: |
| 23 | + # Run periodically to catch breakage caused by external changes. |
| 24 | + - cron: "0 3 * * FRI" |
| 25 | + workflow_dispatch: |
| 26 | + repository_dispatch: |
| 27 | + |
| 28 | +jobs: |
| 29 | + run-determination: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + outputs: |
| 32 | + result: ${{ steps.determination.outputs.result }} |
| 33 | + steps: |
| 34 | + - name: Determine if the rest of the workflow should run |
| 35 | + id: determination |
| 36 | + run: | |
| 37 | + if [[ "${{ secrets.ARDUINO_FORUM_API_KEY }}" == "" ]]; then |
| 38 | + # Required API key secret is not defined. |
| 39 | + RESULT="false" |
| 40 | + else |
| 41 | + RESULT="true" |
| 42 | + fi |
| 43 | +
|
| 44 | + echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 45 | +
|
| 46 | + check-order-metadata: |
| 47 | + needs: run-determination |
| 48 | + if: needs.run-determination.outputs.result == 'true' |
| 49 | + runs-on: ubuntu-latest |
| 50 | + env: |
| 51 | + ARTIFACT_NAME: category-order-metadata |
| 52 | + CATEGORY_ORDER_METADATA_FILE_PATH: content/categories/order.md |
| 53 | + steps: |
| 54 | + - name: Checkout repository |
| 55 | + uses: actions/checkout@v3 |
| 56 | + |
| 57 | + - name: Install Poetry |
| 58 | + run: | |
| 59 | + pipx install \ |
| 60 | + --python "$(which python)" \ |
| 61 | + poetry |
| 62 | +
|
| 63 | + - name: Install Task |
| 64 | + uses: arduino/setup-task@v1 |
| 65 | + with: |
| 66 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + version: 3.x |
| 68 | + |
| 69 | + - name: Generate category order metadata |
| 70 | + env: |
| 71 | + ARDUINO_FORUM_API_KEY: ${{ secrets.ARDUINO_FORUM_API_KEY }} |
| 72 | + run: | |
| 73 | + task \ |
| 74 | + --silent \ |
| 75 | + forum:generate-category-order-metadata |
| 76 | +
|
| 77 | + - name: Check category order metadata |
| 78 | + id: check-category-order-metadata |
| 79 | + run: git diff --color --exit-code |
| 80 | + |
| 81 | + - name: Upload corrected file to workflow artifact |
| 82 | + if: failure() && steps.check-category-order-metadata.outcome == 'failure' |
| 83 | + uses: actions/upload-artifact@v3 |
| 84 | + with: |
| 85 | + if-no-files-found: error |
| 86 | + name: ${{ env.ARTIFACT_NAME }} |
| 87 | + path: ${{ env.CATEGORY_ORDER_METADATA_FILE_PATH }} |
| 88 | + |
| 89 | + - name: Add artifact availability notice |
| 90 | + if: failure() && steps.check-category-order-metadata.outcome == 'failure' |
| 91 | + run: | |
| 92 | + echo "::notice file=${{ env.CATEGORY_ORDER_METADATA_FILE_PATH }}::Corrected file was saved to the ${{ env.ARTIFACT_NAME }} workflow artifact" |
0 commit comments