|
1 | | -# Check for changes in the upstream template. If changes are found, an issue is created |
2 | | -name: Template check. |
| 1 | +# Check for changes in the upstream template. If changes are found, an issue is created. |
| 2 | +name: Template check |
| 3 | + |
3 | 4 | on: |
| 5 | + workflow_dispatch: |
4 | 6 | schedule: |
5 | 7 | - cron: '0 0 1 * *' # Runs at 00:00 UTC on the 1st day of every month |
6 | 8 |
|
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 12 | + |
7 | 13 | jobs: |
8 | | - copier-update: |
9 | | - uses: modelblocks-org/data-module-template/.github/workflows/template-check-version.yml@latest |
| 14 | + copier-check-update: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + issues: write |
| 19 | + env: |
| 20 | + ISSUE_TITLE: Template update available |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Install uv |
| 25 | + uses: astral-sh/setup-uv@v5 |
| 26 | + |
| 27 | + - name: Check for template updates |
| 28 | + id: copier_check_update |
| 29 | + run: | |
| 30 | + update_json="$(uvx --from 'copier>=9.15.2' copier check-update --output-format json)" |
| 31 | + echo "$update_json" |
| 32 | + { |
| 33 | + echo "update_available=$(jq -r '.update_available // false' <<< "$update_json")" |
| 34 | + echo "current_version=$(jq -r '.current_version // "unknown"' <<< "$update_json")" |
| 35 | + echo "latest_version=$(jq -r '.latest_version // "unknown"' <<< "$update_json")" |
| 36 | + } >> "$GITHUB_OUTPUT" |
| 37 | +
|
| 38 | + - name: Check for existing update issue |
| 39 | + if: steps.copier_check_update.outputs.update_available == 'true' |
| 40 | + id: existing_issue |
| 41 | + run: | |
| 42 | + issue_count="$(gh issue list \ |
| 43 | + --repo "${{ github.repository }}" \ |
| 44 | + --state open \ |
| 45 | + --search "$ISSUE_TITLE in:title" \ |
| 46 | + --json title \ |
| 47 | + --jq "map(select(.title == \"$ISSUE_TITLE\")) | length")" |
| 48 | + if [[ "$issue_count" -gt 0 ]]; then |
| 49 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 50 | + else |
| 51 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 52 | + fi |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Open update issue |
| 57 | + if: steps.copier_check_update.outputs.update_available == 'true' && steps.existing_issue.outputs.exists != 'true' |
| 58 | + run: | |
| 59 | + gh issue create \ |
| 60 | + --repo "${{ github.repository }}" \ |
| 61 | + --title "$ISSUE_TITLE" \ |
| 62 | + --body "A new version of the Modelblocks data module template is available. |
| 63 | +
|
| 64 | + Current template version: ${{ steps.copier_check_update.outputs.current_version }} |
| 65 | + Latest template version: ${{ steps.copier_check_update.outputs.latest_version }} |
| 66 | +
|
| 67 | + Please update this project using: |
| 68 | +
|
| 69 | + \`\`\`shell |
| 70 | + copier update --skip-answered --defaults |
| 71 | + \`\`\` |
| 72 | +
|
| 73 | + Review the resulting changes before merging them." |
| 74 | + env: |
| 75 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments