Check AnkiConnect Update #167
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: Check AnkiConnect Update | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' | |
| workflow_dispatch: {} | |
| jobs: | |
| check-update: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| issues: write | |
| steps: | |
| - name: Get AnkiConnect latest version | |
| id: ankiconnect | |
| run: | | |
| # Get latest tag (e.g., 25.11.9.0) | |
| TAG=$(git ls-remote --tags --sort=-v:refname https://git.sr.ht/~foosoft/anki-connect | head -n 1 | cut -f2 | sed 's|refs/tags/||') | |
| echo "Latest tag: $TAG" | |
| # Parse YY.MM.D.patch into a date | |
| IFS='.' read -r YY MM D PATCH <<< "$TAG" | |
| # Convert 2-digit year to 4-digit (assuming 20xx) | |
| YYYY="20$YY" | |
| # Pad month and day with leading zeros for proper date comparison | |
| MM=$(printf "%02d" "$MM") | |
| DD=$(printf "%02d" "$D") | |
| ANKICONNECT_DATE="$YYYY-$MM-$DD" | |
| echo "Parsed date: $ANKICONNECT_DATE" | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "date=$ANKICONNECT_DATE" >> $GITHUB_OUTPUT | |
| - name: Get latest release date | |
| id: release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| # Get the latest release from the current repository | |
| RELEASE_INFO=$(gh release view --repo ${{ github.repository }} --json publishedAt,tagName 2>/dev/null || echo "") | |
| if [ -z "$RELEASE_INFO" ]; then | |
| echo "No releases found" | |
| echo "date=1970-01-01" >> $GITHUB_OUTPUT | |
| else | |
| # Extract the date part (YYYY-MM-DD) from the ISO timestamp | |
| RELEASE_DATE=$(echo "$RELEASE_INFO" | jq -r '.publishedAt' | cut -d'T' -f1) | |
| TAG_NAME=$(echo "$RELEASE_INFO" | jq -r '.tagName') | |
| echo "Latest release: $TAG_NAME published on $RELEASE_DATE" | |
| echo "date=$RELEASE_DATE" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Compare dates and create issue if needed | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| ANKICONNECT_DATE: ${{ steps.ankiconnect.outputs.date }} | |
| ANKICONNECT_TAG: ${{ steps.ankiconnect.outputs.tag }} | |
| RELEASE_DATE: ${{ steps.release.outputs.date }} | |
| run: | | |
| echo "AnkiConnect update date: $ANKICONNECT_DATE (tag: $ANKICONNECT_TAG)" | |
| echo "Latest release date: $RELEASE_DATE" | |
| # Convert dates to comparable format (seconds since epoch) | |
| ANKI_EPOCH=$(date -d "$ANKICONNECT_DATE" +%s) | |
| RELEASE_EPOCH=$(date -d "$RELEASE_DATE" +%s) | |
| if [ "$ANKI_EPOCH" -gt "$RELEASE_EPOCH" ]; then | |
| echo "AnkiConnect has been updated since the last release!" | |
| ISSUE_TITLE="Evaluate New AnkiConnect Version: $ANKICONNECT_DATE" | |
| # Check if an issue with this title already exists | |
| EXISTING_ISSUE=$(gh issue list --repo ${{ github.repository }} --search "\"$ISSUE_TITLE\"" --state open --json number --jq '.[0].number') | |
| if [ -n "$EXISTING_ISSUE" ]; then | |
| echo "Issue already exists: #$EXISTING_ISSUE" | |
| else | |
| # Construct the body using a Heredoc | |
| ISSUE_BODY=$(cat <<EOF | |
| A new version of AnkiConnect was detected. | |
| **AnkiConnect Version:** \`$ANKICONNECT_TAG\` | |
| **AnkiConnect Date:** $ANKICONNECT_DATE | |
| **Last Release Date:** $RELEASE_DATE | |
| **Source:** https://git.sr.ht/~foosoft/anki-connect | |
| --- | |
| *This issue was automatically created by the AnkiConnect update checker workflow.* | |
| EOF | |
| ) | |
| # Create the issue using the variable | |
| gh issue create \ | |
| --repo ${{ github.repository }} \ | |
| --title "$ISSUE_TITLE" \ | |
| --body "$ISSUE_BODY" | |
| echo "Created new issue: $ISSUE_TITLE" | |
| fi | |
| else | |
| echo "No new AnkiConnect update detected." | |
| fi |