diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 84c87d635..000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: 2 -updates: - - package-ecosystem: "docker" - directory: "/" - schedule: - interval: "weekly" diff --git a/.github/renovate.json b/.github/renovate.json index ccdb38ae5..1e474c7c8 100644 --- a/.github/renovate.json +++ b/.github/renovate.json @@ -10,5 +10,27 @@ ], "extends": [ "local>sourcegraph/renovate-config" + ], + "timezone": "Europe/Warsaw", + "schedule": [ + "before 9am on monday" + ], + "packageRules": [ + { + "description": "Merge non-major updates once all checks pass; major updates need review. Renovate merges them itself: GitHub auto-merge would only wait for the required snapshot tests, not the Docker image build.", + "matchUpdateTypes": ["minor", "patch", "digest", "pin", "pinDigest"], + "automerge": true, + "platformAutomerge": false + }, + { + "description": "The shared preset auto-merges some npm updates of every type; keep major updates for review.", + "matchUpdateTypes": ["major"], + "automerge": false + }, + { + "description": "Update GitHub Actions and the tool versions they install in one PR.", + "matchManagers": ["github-actions"], + "groupName": "GitHub Actions" + } ] } diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml new file mode 100644 index 000000000..22ba1cf4a --- /dev/null +++ b/.github/workflows/scheduled-release.yml @@ -0,0 +1,69 @@ +name: scheduled-release + +# Opens a patch release PR every 4 weeks on Monday, even without code changes, +# so the Docker image is rebuilt with the latest Alpine package updates. +# Merging the PR publishes the release (see tag-release.yml). +on: + # Cron can't express "every 4 weeks", so this runs every Monday + # and skips weeks that aren't a multiple of 4 after RELEASE_MONDAY. + schedule: + - cron: '0 9 * * 1' + workflow_dispatch: + +env: + RELEASE_MONDAY: '2026-11-23' + +permissions: + contents: write + pull-requests: write + +jobs: + open-release-pr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + # Release from scip even when dispatched from another branch. + ref: scip + fetch-depth: 0 + + - name: Open release PR + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + if [ "$GITHUB_EVENT_NAME" = "schedule" ]; then + DAYS=$(( ($(date -u +%s) - $(date -u -d "$RELEASE_MONDAY" +%s)) / 86400 )) + if (( DAYS % 28 != 0 )); then + echo "Not a release week ($DAYS days after $RELEASE_MONDAY)" + exit 0 + fi + fi + + ./dev/prepare_release.sh + VERSION="$(jq -r .version packages/pyright-scip/package.json)" + BRANCH="release/v$VERSION" + + # A separate assignment, so a failed lookup stops the job under set -e. + OPEN_PR="$(gh pr list --head "$BRANCH" --state open --json number --jq '.[].number')" + if [ -n "$OPEN_PR" ]; then + echo "::warning::PR #$OPEN_PR for $BRANCH is already open; merge or close it first." + exit 0 + fi + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git checkout -b "$BRANCH" + git commit -am "release/v$VERSION" + # With no open PR, a leftover branch (from a run that failed after pushing, + # or a PR closed without deleting it) is stale, so replace it. + git push --force origin "$BRANCH" + + gh pr create --base scip --head "$BRANCH" --title "release/v$VERSION" --body "$(cat <>"$GITHUB_OUTPUT" - name: Build and push id: docker_build_autoindex uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0 @@ -33,7 +67,4 @@ jobs: context: . file: Dockerfile.autoindex push: true - tags: | - sourcegraph/scip-python:autoindex - sourcegraph/scip-python:latest - sourcegraph/scip-python:${{ github.ref_name }} + tags: ${{ steps.docker_tags.outputs.tags }} diff --git a/.github/workflows/tag-release.yml b/.github/workflows/tag-release.yml new file mode 100644 index 000000000..a7d97431a --- /dev/null +++ b/.github/workflows/tag-release.yml @@ -0,0 +1,52 @@ +name: tag-release + +# Tags a release when a version bump in package.json lands on scip. +on: + push: + branches: + - scip + paths: + - 'packages/pyright-scip/package.json' + +permissions: + contents: write + actions: write + +jobs: + tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Tag release + env: + GH_TOKEN: ${{ github.token }} + run: | + set -euo pipefail + TAG="v$(jq -r .version packages/pyright-scip/package.json)" + if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then + # A rerun of this workflow finds its own tag; publish again. + # Other package.json changes, such as dependency bumps, find an older tag. + if [ "$(git rev-parse "$TAG^{commit}")" != "$GITHUB_SHA" ]; then + echo "$TAG already exists on an earlier commit; nothing to release" + exit 0 + fi + else + # Catch hand-edited versions, such as v0.6.9 or an older release. + LATEST="$(git tag --list 'v[0-9]*' | sort -V | tail -n 1)" + if ! [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || + [ "$(printf '%s\n%s\n' "$LATEST" "$TAG" | sort -V | tail -n 1)" != "$TAG" ]; then + echo "$TAG is not of the form vM.N.P or isn't newer than $LATEST" + exit 1 + fi + git tag "$TAG" "$GITHUB_SHA" + git push origin "$TAG" + fi + + # Tags pushed with GITHUB_TOKEN don't trigger workflows, so start the + # release for the tag explicitly. Don't call scip-release.yml as a + # reusable workflow instead: npm trusted publishing would then check + # this workflow's file name and reject the publish. + gh workflow run scip-release.yml --ref "$TAG" diff --git a/Dockerfile.autoindex b/Dockerfile.autoindex index b79ed53fe..69bbb2312 100644 --- a/Dockerfile.autoindex +++ b/Dockerfile.autoindex @@ -1,8 +1,9 @@ FROM nikolaik/python-nodejs:python3.11-nodejs24-alpine@sha256:f5f3688c6a25b348ed196cc159bf7fa0538454a7d8775560bc4052d57c971645 +# Upgrade the base image's packages too, so every rebuild picks up Alpine security updates. # ca-certificates 20261020-r0 distrusts the compromised eMudhra intermediates; # the base image ships an older version. -RUN apk add --no-cache --upgrade git bash curl 'ca-certificates>=20261020-r0' 'ca-certificates-bundle>=20261020-r0' +RUN apk upgrade --no-cache && apk add --no-cache --upgrade git bash curl 'ca-certificates>=20261020-r0' 'ca-certificates-bundle>=20261020-r0' # Install scip-python from this checkout (run `npm pack` in packages/pyright-scip # first), not from npm: npm holds new versions for malware scanning, so a # release build would otherwise install the previous version. diff --git a/dev/bump_version.sh b/dev/bump_version.sh deleted file mode 100755 index ebf6ebe7a..000000000 --- a/dev/bump_version.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/bash - -set -e - -if ! git diff --quiet; then - echo "=======================================" - echo " Please clean up your dirty repo" - echo "=======================================" - exit 1 -fi - -read -p "set version to > " -r VERSION - -if [[ $VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]$ ]]; then - echo "valid version: $VERSION" -else - echo "Invalid semver specifier. Expected 'v0.0.0'" - exit 1 -fi - -# shellcheck disable=SC2001 -# Use sed, cause it's OK -PACKAGE_VERSION=$(echo "$VERSION" | sed 's/^v//') -eval "cd packages/pyright-scip/ && yarn version --no-git-tag-version --new-version $PACKAGE_VERSION" - -git commit -am "bump version: $VERSION" -git push - -git tag -fa "$VERSION" -m "$VERSION" -git push -f origin "$VERSION" diff --git a/dev/prepare_release.sh b/dev/prepare_release.sh new file mode 100755 index 000000000..0dbdb8f89 --- /dev/null +++ b/dev/prepare_release.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Bumps the scip-python version and adds an editable CHANGELOG entry +# listing the commits since the latest release tag. +# +# Inputs: +# NEW_VERSION (optional) should be a string M.N.P. Defaults to the +# next patch version after the latest release tag. + +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/../packages/pyright-scip" + +LAST_TAG="$(git describe --tags --abbrev=0 --match 'v[0-9]*')" +IFS=. read -r MAJOR MINOR PATCH <<<"${LAST_TAG#v}" +NEW_VERSION="${NEW_VERSION:-$MAJOR.$MINOR.$((PATCH + 1))}" + +if ! [[ "$NEW_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "error: NEW_VERSION=$NEW_VERSION is not of the form M.N.P" + exit 1 +fi +if [ "$(printf '%s\n%s\n' "${LAST_TAG#v}" "$NEW_VERSION" | sort -V | tail -n 1)" != "$NEW_VERSION" ] || + [ "$NEW_VERSION" = "${LAST_TAG#v}" ]; then + echo "error: NEW_VERSION=$NEW_VERSION must be newer than the latest release $LAST_TAG" + exit 1 +fi + +# Update package.json and package-lock.json before the CHANGELOG: npm version fails +# when they already have NEW_VERSION, as on a second run, so no duplicate entry is added. +npm version "$NEW_VERSION" --no-git-tag-version --ignore-scripts >/dev/null + +# Renovate updates are covered by the Docker image line. +CHANGES="$(git log --format='- %s' "$LAST_TAG..HEAD" | grep -v '^- chore(deps)' || true)" +ENTRY="$(printf '## v%s\n\n- Rebuilds the Docker image with the latest Alpine package updates.\n%s' "$NEW_VERSION" "$CHANGES")" + +# ENVIRON, unlike awk -v, keeps backslashes in commit subjects as they are. +ENTRY="$ENTRY" awk ' + !inserted && /^## v/ { + print ENVIRON["ENTRY"] "\n" + inserted = 1 + } + { print } +' CHANGELOG.md >CHANGELOG.md.new +mv CHANGELOG.md.new CHANGELOG.md + +echo "Prepared release v$NEW_VERSION" diff --git a/packages/pyright-scip/CONTRIBUTING.md b/packages/pyright-scip/CONTRIBUTING.md index 0f3c7c59e..880d59d29 100644 --- a/packages/pyright-scip/CONTRIBUTING.md +++ b/packages/pyright-scip/CONTRIBUTING.md @@ -113,9 +113,23 @@ When modifying code in the `pyright-internal` package: ## Publishing releases -1. Create a PR with the following changes: +A [scheduled workflow](/.github/workflows/scheduled-release.yml) +opens a patch release PR every 4 weeks on Monday, even without code changes, +so the Docker image picks up the latest Alpine package updates. +It can also be run on demand from the +[GitHub Actions UI](https://github.com/sourcegraph/scip-python/actions/workflows/scheduled-release.yml). +GitHub doesn't run CI on that PR until you select +**Approve workflows to run** on it. + +1. Create a PR with the following changes (the scheduled PR already has both): - Change the version in [package.json](./package.json) to `M.N.P`. - Add release notes to [CHANGELOG.md](./CHANGELOG.md) -2. After merging the PR, add a tag `vM.N.P` to the latest - commit on the `scip` branch and push that tag. + + To prepare one by hand, run `NEW_VERSION="M.N.P" ./dev/prepare_release.sh` + from the repository root (without `NEW_VERSION`, it bumps the patch version) + and edit the CHANGELOG entry. +2. Once the PR is merged to `scip`, the [tag workflow](/.github/workflows/tag-release.yml) + pushes the `vM.N.P` tag and starts the + [release workflow](/.github/workflows/scip-release.yml), + which publishes the npm package and the Docker images.