Check latest release version of tree-sitter. #77
This file contains 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 latest release version of tree-sitter. | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: 'Version to compare with the latest release (for test purposes)' | |
required: false | |
default: '0.22.4' | |
schedule: | |
- cron: "0 0 * * *" | |
pull_request: | |
paths: | |
- ".github/workflows/check-new-release.yml" | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
outputs: | |
should-run: ${{ steps.compare_versions.outputs.should-run }} | |
new-version: ${{ steps.compare_versions.outputs.new-version }} | |
steps: | |
- name: Fetch the latest release version of tree-sitter. | |
id: fetch_latest_release | |
run: | | |
gh release list \ | |
--repo tree-sitter/tree-sitter \ | |
-L 1 \ | |
-O desc \ | |
--json tagName \ | |
--jq '.[0].tagName' > latest_version | |
- name: Fetch the release currently supported by tree-sitter-bazel. | |
id: fetch_current_supported_release | |
run: | | |
curl "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/contents/VERSION" \ | |
| jq -r ".content" \ | |
| base64 --decode | (echo -ne 'v' && cat -) > current_version | |
- name: Override the current version if specified in `workflow_dispatch`. | |
id: override_current_version | |
if: "${{ github.event.inputs.version != '' }}" | |
run: echo "v${{ github.event.inputs.version }}" > current_version | |
- name: Compare versions. | |
id: compare_versions | |
run: | | |
LATEST_VERSION="$(<latest_version)" | |
CURRENT_VERSION="$(<current_version)" | |
printf 'Current version: %s\nLatest version: %s\n' "${CURRENT_VERSION}" "${LATEST_VERSION}" | |
if [ "${LATEST_VERSION}" = "${CURRENT_VERSION}" ]; then | |
echo "Up to date with ${CURRENT_VERSION}" | |
echo "should-run=false" >> $GITHUB_OUTPUT | |
echo "new-version=${LATEST_VERSION}" >> $GITHUB_OUTPUT | |
else | |
echo "A new release is available: ${LATEST_VERSION}" | |
echo "should-run=true" >> $GITHUB_OUTPUT | |
echo "new-version=${LATEST_VERSION}" >> $GITHUB_OUTPUT | |
fi | |
open-issue: | |
runs-on: ubuntu-latest | |
needs: check-version | |
if: needs.check-version.outputs.should-run == 'true' | |
permissions: | |
issues: write | |
env: | |
GH_TOKEN: ${{ github.token }} | |
TITLE_FMT: Update to latest release %s | |
steps: | |
- name: Open a new issue if necessary. | |
id: new_issue | |
run: | | |
version="${{ needs.check-version.outputs.new-version }}" | |
title="$(printf "${TITLE_FMT}" "${version}")" | |
issue_id="$(gh issue list --repo "${GITHUB_REPOSITORY}" --search 'is:issue is:open "'"${title}"'"' --json number -q '.[0].number')" | |
if [ -n "${issue_id}" ]; then | |
printf 'issue already exists for %s: %u' "${version}" "${issue_id}" | |
exit 0 | |
fi | |
gh issue create --title "${title}" --body "See [${version}](https://github.com/tree-sitter/tree-sitter/releases/tag/${version})" --repo "${GITHUB_REPOSITORY}" |