Update Microdata Tools Version #831
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Microdata Tools Version | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| on: | |
| schedule: | |
| - cron: 0 10 * * * # Runs everyday at 10:00 | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| jobs: | |
| update-dependency: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Ensure the full history is fetched | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.13" | |
| - name: Install the latest version of uv | |
| uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2 | |
| - name: Sync dependencies | |
| run: uv sync | |
| - name: Check for New Version | |
| id: check_version | |
| run: | | |
| CURRENT_VERSION=$(uv pip list --format json | jq -r '.[] | select(.name=="microdata-tools") | .version') | |
| LATEST_VERSION=$(curl -s https://pypi.org/pypi/microdata-tools/json | jq -r .info.version) | |
| echo "Current version: $CURRENT_VERSION" | |
| echo "Latest version: $LATEST_VERSION" | |
| if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then | |
| echo "NEW_VERSION=$LATEST_VERSION" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Already up-to-date" | |
| exit 0 | |
| fi | |
| - name: Get Change Log | |
| if: steps.check_version.outputs.NEW_VERSION | |
| id: get_change_log | |
| env: | |
| NEW_VERSION: ${{ steps.check_version.outputs.NEW_VERSION }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| RELEASE_DATA=$(gh release view "v$NEW_VERSION" --repo statisticsnorway/microdata-tools --json body,url) | |
| # Replace #123 with full repo reference so GitHub links to the correct repo | |
| CHANGELOG=$(echo "$RELEASE_DATA" | jq -r '.body' | sed 's/#\([0-9]\)/statisticsnorway\/microdata-tools#\1/g') | |
| RELEASE_URL=$(echo "$RELEASE_DATA" | jq -r '.url') | |
| { | |
| echo "CHANGELOG<<EOF" | |
| echo "$CHANGELOG" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| echo "RELEASE_URL=$RELEASE_URL" >> "$GITHUB_OUTPUT" | |
| - name: Update Microdata Tools Dependency | |
| if: steps.check_version.outputs.NEW_VERSION | |
| env: | |
| NEW_VERSION: ${{ steps.check_version.outputs.NEW_VERSION }} | |
| run: | | |
| git config --global user.name 'github-actions' | |
| git config --global user.email 'github-actions@github.com' | |
| git pull origin main | |
| git checkout -b "bump-microdata-tools-$NEW_VERSION" | |
| uv add "microdata-tools==$NEW_VERSION" | |
| git add pyproject.toml uv.lock | |
| git commit -m "Update microdata-tools to $NEW_VERSION" | |
| git push origin "bump-microdata-tools-$NEW_VERSION" | |
| - name: Create Pull Request | |
| if: steps.check_version.outputs.NEW_VERSION | |
| env: | |
| NEW_VERSION: ${{ steps.check_version.outputs.NEW_VERSION }} | |
| CHANGELOG: ${{ steps.get_change_log.outputs.CHANGELOG }} | |
| RELEASE_URL: ${{ steps.get_change_log.outputs.RELEASE_URL }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| PR_BODY="This PR updates microdata-tools to version $NEW_VERSION. | |
| $CHANGELOG | |
| [View the changelog for $NEW_VERSION in the microdata-tools repository.]($RELEASE_URL)" | |
| gh pr create \ | |
| --base main \ | |
| --head "bump-microdata-tools-$NEW_VERSION" \ | |
| --title "Update microdata-tools to $NEW_VERSION" \ | |
| --body "$PR_BODY" |