diff --git a/.github/workflows/vcheck.yml b/.github/workflows/vcheck.yml index 99ab0a156..687164f6f 100644 --- a/.github/workflows/vcheck.yml +++ b/.github/workflows/vcheck.yml @@ -1,43 +1,71 @@ -name: Check Turing.jl Version +name: Check Turing.jl version on: + push: + branches: + - master + - backport-* pull_request: - paths: ['_quarto.yml'] + branches: + - master + - backport-* workflow_dispatch: jobs: check-version: runs-on: ubuntu-latest + + # Determine whether the target branch is master. If so, also make sure to check that the + # version matches the latest release of Turing.jl. + env: + TARGET_IS_MASTER: ${{ (github.event_name == 'push' && github.ref_name == 'master') || (github.event_name == 'pull_request' && github.base_ref == 'master') }} + steps: - name: Checkout uses: actions/checkout@v4 - - name: Extract current minor version - id: extract_minor_version + - name: Setup Julia + uses: julia-actions/setup-julia@v2 + + - name: Log GitHub context variables run: | - minor_version=$(grep -oP 'text:\s+"v\K\d+\.\d+' _quarto.yml) - echo "MINOR_VERSION=$minor_version" >> $GITHUB_OUTPUT + echo github.event_name: ${{ github.event_name }} + echo github.ref_name: ${{ github.ref_name }} + echo github.base_ref: ${{ github.base_ref }} + echo TARGET_IS_MASTER: ${{ env.TARGET_IS_MASTER }} - - name: Fetch latest minor version - id: fetch_latest_minor + - name: Check version consistency between Project.toml, _quarto.yml, and GitHub release + shell: julia --color=yes --project=. {0} run: | - repo_url="https://api.github.com/repos/TuringLang/Turing.jl/releases/latest" - latest=$(curl -s $repo_url | jq -r .tag_name) - actual_latest_minor=${latest%.*} - echo "LATEST_MINOR=$actual_latest_minor" >> $GITHUB_OUTPUT - echo "LATEST=$latest" >> $GITHUB_OUTPUT + using Pkg + Pkg.activate(temp=true) + Pkg.add(["YAML", "TOML", "JSON", "HTTP"]) + import YAML + import TOML + import JSON + import HTTP - - name: Update _quarto.yml if outdated - run: | - minor_version=${{ steps.extract_minor_version.outputs.MINOR_VERSION }} - latest_minor=${{ steps.fetch_latest_minor.outputs.LATEST_MINOR }} - if [ "$minor_version" != "$latest_minor" ]; then - awk -v old="v$minor_version" -v new="$latest_minor" '{gsub(old, new); print}' _quarto.yml > temp.yml && mv temp.yml _quarto.yml - echo "Updated _quarto.yml to latest minor version: $latest_minor" - fi - - - name: Suggest Changes - uses: getsentry/action-git-diff-suggestions@main - with: - message: 'The version in _quarto.yml is outdated. Please update to the latest version.' - github-token: ${{ secrets.GITHUB_TOKEN }} - continue-on-error: true + function major_minor_match(v1::VersionNumber, v2::VersionNumber) + return v1.:major == v2.:major && v1.:minor == v2.:minor + end + + quarto_yaml = YAML.load_file("_quarto.yml") + quarto_version = VersionNumber(quarto_yaml["website"]["navbar"]["right"][1]["text"]) + println("_quarto.yml version: ", quarto_version) + + project_toml = TOML.parsefile("Project.toml") + project_version = VersionNumber(project_toml["compat"]["Turing"]) + println("Project.toml version: ", project_version) + + if ENV["TARGET_IS_MASTER"] == "true" + resp = HTTP.get("https://api.github.com/repos/TuringLang/Turing.jl/releases/latest") + latest_version = VersionNumber(JSON.parse(String(resp.body))["tag_name"]) + println("Latest Turing.jl version: ", latest_version) + if !major_minor_match(latest_version, project_version) || !major_minor_match(latest_version, quarto_version) + error("The latest version of Turing.jl (as determined from GitHub releases) is $latest_version. + * Please update Project.toml and/or _quarto.yml to match this version.") + end + else + if !major_minor_match(quarto_version, project_version) + error("The versions of Turing.jl in _quarto.yml and Project.toml do not match.") + end + end