Housekeeping actions#

Housekeeping actions provide for general repository operations such as package cleanup.

Package cleanup of untagged versions#

Action cleaning up untagged package versions published at ghcr.io.

Important

Required GitHub Permissions

  • packages: delete - Required to delete package versions from GitHub Container Registry (GHCR)

Source code for this action

Input

Description

Required

Type

Default

package-name

Package name.

True

string

token

Token with package deletion permissions.

True

string

package-org

Organization where packages are published.

False

string

ansys

allow-last-days

Avoid removing the last N days images: e.g. ‘2’.

False

string

Examples#

Perform untagged versions cleanup
hk-package-clean-untagged:
  name: "Perform untagged versions cleanup"
  runs-on: ubuntu-latest
  permissions:
    packages: delete  # Required to delete package versions from GitHub Container Registry (GHCR)
  steps:
    - name: "Perform untagged versions cleanup"
      uses: ansys/actions/hk-package-clean-untagged@v11.2
      with:
        package-name: 'mypackage'
        token: ${{ secrets.GITHUB_TOKEN }}

Package cleanup excluding certain versions#

“Action cleaning up all package versions published at ghcr.io except for certain tags.”

Note

If an image matched by tags-kept has multiple tags (which are potentially not in the tags-kept list), then the entire image (with all its tags) will be kept.

Important

Required GitHub Permissions

  • packages: delete - Required to delete package versions from GitHub Container Registry (GHCR)

Source code for this action

Input

Description

Required

Type

Default

package-name

Package name.

True

string

token

Token with package deletion permissions.

True

string

tags-kept

Tags to be kept. Pass them as a list: e.g. ‘latest, latest-unstable’.

True

string

package-org

Organization at which packages are published.

False

string

ansys

allow-last-days

Avoid removing the last N days images: e.g. ‘2’.

False

string

Examples#

Perform versions cleanup - except certain tags
hk-package-clean-except:
  name: "Perform versions cleanup - except certain tags"
  runs-on: ubuntu-latest
  permissions:
    packages: delete  # Required to delete package versions from GitHub Container Registry (GHCR)
  steps:
    - name: "Perform versions cleanup - except certain tags"
      uses: ansys/actions/hk-package-clean-except@v11.2
      with:
        package-name: 'mypackage'
        token: ${{ secrets.GITHUB_TOKEN }}
        tags-kept: 'latest, latest-unstable'

Auto-merge pull requests#

Action merging dependabot and pre-commit.ci PRs.

Important

Required GitHub Permissions

  • contents: write - Required to merge pull requests

  • pull-requests: write - Required to approve and enable auto-merge on pull requests

Source code for this action

Input

Description

Required

Type

Default

approver

Approver GitHub ID.

True

string

approver-token

Approver GitHub token.

True

string

only-allow-dependabot-patch

Only allow dependabot patch version updates. By default, this is set to false (allowing also minor bumps).

False

boolean

False

Examples#

Automerging dependabot and pre-commit.ci PRs
hk-automerge-prs:
  name: "Automerging dependabot and pre-commit.ci PRs"
  runs-on: ubuntu-latest
  # Only runs if we are on a PR
  if: github.event_name == 'pull_request'
  permissions:
    contents: write  # Required to merge pull requests
    pull-requests: write  # Required to approve and enable auto-merge on pull requests
  steps:
    - name: "Automerging dependabot and pre-commit.ci PRs"
      uses: ansys/actions/hk-automerge-prs@v11.2
      with:
        approver: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
        approver-token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}

Migrate fork pull requests#

Migrates pull requests from forks to branches within the main repository, enabling workflows that require repository secrets to run. This action handles team membership verification and automated PR creation during migration. After migration, triggering the action subsequently will sync the migration branch with the latest changes from the fork branch.

When syncing, the migration branch is kept as a mirror of the fork branch. This means than any changes pushed to the fork branch will be reflected in the migration branch after a sync, and any changes made directly to the migration branch (e.g., by maintainers) will be overwritten on the next sync.

Note

This action is designed to be called from workflows triggered by issue comments.

Important

Required GitHub Permissions

  • contents: write - Required to push migration branches to the main repository

  • pull-requests: write - Required to create pull requests, add comments, and manage reactions

Additionally, the provided github-token must have read:org scope to check team membership for authorization.

Source code for this action

Input

Description

Required

Type

Default

pr-number

The pull request number to migrate. This should be the PR number from the fork that needs to be migrated to the main repository.

True

string

comment-id

The comment ID that triggered the migration. Used for adding reactions to indicate success or failure.

True

string

user-triggering

The GitHub username of the user triggering the migration. This user will be verified for team membership before proceeding.

True

string

github-token

GitHub token with permissions to create branches, push code, create pull requests, manage comments/reactions, and check team membership. Typically a bot token with contents: write, pull-requests: write, and read:org permissions.

True

string

bot-username

The username of the bot that will be used for git commits during the migration process.

True

string

bot-email

The email address of the bot that will be used for git commits during the migration process.

True

string

team-slug

The slug of the GitHub team that has permission to trigger migrations. For example, pymapdl-maintainers or pyansys-core.

True

string

organization

The GitHub organization name. Defaults to ansys.

False

string

ansys

repository

The repository name (without organization). If not provided, it will be inferred from the GitHub context.

False

string

Examples#

Migrate fork PR to main repository
hk-migrate-fork-pr:
  name: "Migrate fork PR to main repository"
  runs-on: ubuntu-latest
  # Only runs on issue comments
  if: |
    github.event_name == 'issue_comment' &&
    github.event.issue.pull_request != null &&
    (contains(github.event.comment.body, '@pyansys-ci-bot migrate') ||
     contains(github.event.comment.body, '@pyansys-ci-bot sync'))
  permissions:
    contents: write  # Required to push migration branches to the main repository
    pull-requests: write  # Required to create pull requests, add comments, and manage reactions
  steps:
    - name: "Migrate fork PR"
      uses: ansys/actions/hk-migrate-fork-pr@v11.2
      with:
        pr-number: ${{ github.event.issue.number }}
        comment-id: ${{ github.event.comment.id }}
        user-triggering: ${{ github.event.comment.user.login }}
        github-token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
        bot-username: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
        bot-email: ${{ secrets.PYANSYS_CI_BOT_EMAIL }}
        team-slug: 'pyansys-maintainers'

Tag repository version#

Custom action to create latest vX and vX.Y tag to point to the latest released version. A new branch ‘release/vX.Y.Z’ is also pushed to be used for hotfixes.

Important

Required GitHub Permissions

  • contents: write - Required to create and update git tags and release branches

Note

This action is intended to be used in a workflow triggered by a release event. If the release event was created by a different workflow, the workflow using this action may not be triggered.

Source code for this action

Input

Description

Required

Type

Default

gh-token

GitHub token with repo and workflow scope.

True

release-version

Tagged release version to use (typically ‘vX.Y.Z’). If not provided, uses the tag from the GitHub release event.

False

latest-branch-name

Create/update a branch with the latest copy of main. To disable, set to ""

False

latest

Examples#

Tag repository version
hk-tag-repository-version:
  name: "Tag repository version"
  runs-on: ubuntu-latest
  if: github.event_name == 'release'
  permissions:
    contents: write  # Required to push commits, delete and create tags
  steps:
    - uses: actions/checkout@v6
      with:
        fetch-depth: 0
        fetch-tags: true
    - name: vX.Y version from tag
      shell: bash
      id: major_minor_version
      env:
        SEMANTIC_VERSION: ${{ github.event.release.tag_name }}
      run: |
        MAJOR_VERSION=$(echo ${SEMANTIC_VERSION} |  cut -d 'v' -f 2 | cut -d '.' -f 1)
        MINOR_VERSION=$(echo ${SEMANTIC_VERSION} |  cut -d 'v' -f 2 | cut -d '.' -f 2)
        echo "MAJOR_MINOR_VERSION=v${MAJOR_VERSION}.${MINOR_VERSION}" >> $GITHUB_OUTPUT
    - name: "Update latest vX and vX.Y tag"
      uses: ansys/actions/hk-tag-repository-version@v11.2
      with:
        gh-token: ${{ secrets.GITHUB_TOKEN }}
        latest-branch-name: release/${{ steps.major_minor_version.outputs.MAJOR_MINOR_VERSION }}
Tag repository version
hk-tag-repository-version:
  name: "Tag repository version"
  runs-on: ubuntu-latest
  if: github.event_name == 'release'
  permissions:
    contents: write  # Required to push commits, delete and create tags
  steps:
    - uses: actions/checkout@v6
      with:
        fetch-depth: 0
        fetch-tags: true
    - name: "Update latest vX and vX.Y tag"
      uses: ansys/actions/hk-tag-repository-version@v11.2
      with:
        gh-token: ${{ secrets.GITHUB_TOKEN }}
        release-version: ${{ github.event.release.tag_name }}

Auto release#

Automates patch, minor, and major releases: bumps a version recorded in a VERSION file, pyproject.toml, setup.py, or a Python module, creates/updates <release-branch-prefix><major>.<minor> release branches, and pushes the corresponding vX.Y.Z git tag.

  • patch: finds the latest vX.Y.Z tag, merges all commits from the main branch into the matching release branch (this is not a cherry-pick: every commit merged to main since the last minor/major release is included), bumps the patch version, commits, and tags.

  • patch-cherry-pick: like patch, but instead of merging all of main, cherry-picks only the commits listed in cherry-pick-commits (in the order given) onto the release branch.

  • minor/major: creates a new release branch off the main branch with the bumped release version, opens a draft pull request to bump the main branch to the next development version (X.Y.devN), then tags the release branch.

The release tag is the final remote write. If release processing fails, the action attempts to undo its remote writes in reverse order: new branches are deleted, updated release branches are restored only if their remote ref still matches this run’s commit, created pull requests are closed, and a tag created by this run is deleted only if its remote ref still matches. Rollback is best-effort; tag-triggered workflows and other external effects cannot be undone, and any rollback failure is included in the error. If a remote command reports an error after its write may have succeeded (for example, PR creation during a connection failure), verify the remote state before retrying.

Conflicts limited to the version file and lock files are resolved by keeping the release branch’s conflicting hunks while retaining non-conflicting changes. If this leaves a cherry-picked commit with no changes, the action logs that it is skipping the commit and continues with the remaining selected commits.

Important

Required GitHub Permissions

  • contents: write - Required to push commits, branches, and tags

  • pull-requests: write - Required to open the draft pull request that bumps the main branch’s development version

Warning

This action pushes directly to release branches and creates tags; it never pushes directly to the main branch (the main-branch dev-version bump is opened as a draft pull request instead). It must be triggered only by workflow_dispatch, in a workflow file dedicated to this action. Do not add other triggers (such as push, pull_request, or schedule) to that workflow file. The examples below are job definitions to place under jobs: in that dedicated workflow. Each example supports all four release types through the dispatch inputs below. Select the release type when running the workflow; for patch-cherry-pick, also provide comma-separated commit SHAs in the order they should be applied.

on:
  workflow_dispatch:
    inputs:
      release_type:
        description: "Type of release"
        type: choice
        required: true
        default: minor
        options:
          - minor
          - major
          - patch
          - patch-cherry-pick
      cherry_pick_commits:
        description: "Comma-separated commit SHAs, required for patch-cherry-pick"
        type: string
        required: false
        default: ""

Note

Progress messages are flushed immediately to the workflow logs with an [hk-autorelease] prefix. They report version changes, branch/tag pushes, lock file regeneration, merge/cherry-pick operations, automatic conflict resolution, and the draft development-version pull request URL.

Note

This action checks out the repository itself (main-branch, full history, and tags), so the calling workflow does not need an actions/checkout step.

Note

This action only manages version bumping and git branches/tags — it never builds or publishes a package. Pair it with the release-github action (to create the GitHub release) and release-pypi-public (or a trusted-publisher based workflow) to actually publish the artifacts, typically triggered separately by the vX.Y.Z tag this action pushes. Because the main-branch dev-version bump is opened as a draft pull request (see the dev-version-pr-url output), merging it is a manual, separate step you should only take once you’ve confirmed the release was published successfully.

Source code for this action

Input

Description

Required

Type

Default

release-type

Type of release to perform. One of patch (merges all commits from the main branch into the release branch), patch-cherry-pick (cherry-picks only the commits listed in cherry-pick-commits onto the release branch), minor, or major.

True

string

version-source

Where the version is stored. One of file (a plain text file whose entire content is the version, e.g. a VERSION file), pyproject (the project.version key of a pyproject.toml file), setup-py (the version= keyword argument in a setup.py file), or python-module (a __version__ = "..." assignment in a Python module).

True

string

version-location

Path, relative to the repository root, to the file identified by version-source.

True

string

token

GitHub token used to verify repository permissions, check out the repository, push commits/branches/tags, and open the dev-version bump pull request.

True

string

bot-username

Username used as the git commit author for release and version bump commits.

True

string

bot-email

Email used as the git commit author for release and version bump commits.

True

string

main-branch

Name of the main development branch.

False

string

main

release-branch-prefix

Prefix used to compute release branch names: <release-branch-prefix><major>.<minor>.

False

string

release/

cherry-pick-commits

Comma-separated list of commit SHAs to cherry-pick into the release branch, in order. Required when release-type is patch-cherry-pick; ignored otherwise.

False

string

lock-file-tool

Lock file tooling to regenerate alongside each version bump. One of none (default, skip lock file regeneration), uv (runs uv lock), or poetry (runs uvx poetry lock --no-update). Neither command upgrades dependencies; they only re-resolve the lock file against the already-bumped project metadata. The command runs in the directory of the nearest pyproject.toml at or above version-location, so the lock file is regenerated next to that pyproject.toml rather than at the repository root.

False

string

none

Examples#

Release regenerating a uv lockfile in a subdirectory
hk-autorelease:
  name: "Release regenerating a uv lockfile in a subdirectory"
  runs-on: ubuntu-latest
  permissions:
    contents: write
    pull-requests: write
  steps:
    - name: "Release and regenerate packages/example/uv.lock"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: pyproject
        version-location: packages/example/pyproject.toml
        lock-file-tool: uv
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}
Release from a Python module’s __version__
hk-autorelease:
  name: "Release from a Python module's __version__"
  runs-on: ubuntu-latest
  permissions:
    contents: write
    pull-requests: write
  steps:
    - name: "Auto release"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: python-module
        version-location: src/ansys/example/_version.py
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}
Release from a VERSION file
hk-autorelease:
  name: "Release from a VERSION file"
  runs-on: ubuntu-latest
  permissions:
    contents: write  # Required to push commits, branches, and tags
    pull-requests: write  # Required to open the dev-version-bump draft pull request
  steps:
    - name: "Auto release"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: file
        version-location: ansys/api/geometry/VERSION
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}
Release regenerating a Poetry lockfile
hk-autorelease:
  name: "Release regenerating a Poetry lockfile"
  runs-on: ubuntu-latest
  permissions:
    contents: write
    pull-requests: write
  steps:
    - name: "Release and regenerate poetry.lock"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: pyproject
        version-location: pyproject.toml
        lock-file-tool: poetry
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}
Release from setup.py
hk-autorelease:
  name: "Release from setup.py"
  runs-on: ubuntu-latest
  permissions:
    contents: write
    pull-requests: write
  steps:
    - name: "Auto release"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: setup-py
        version-location: setup.py
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}
Release from pyproject.toml without lockfile regeneration
hk-autorelease:
  name: "Release from pyproject.toml without lockfile regeneration"
  runs-on: ubuntu-latest
  permissions:
    contents: write
    pull-requests: write
  steps:
    - name: "Auto release"
      uses: ansys/actions/hk-autorelease@v11.2
      with:
        release-type: ${{ inputs.release_type }}
        cherry-pick-commits: ${{ inputs.cherry_pick_commits }}
        version-source: pyproject
        version-location: pyproject.toml
        lock-file-tool: none
        token: ${{ secrets.MY_BOT_TOKEN }}
        bot-username: ${{ secrets.MY_BOT_USERNAME }}
        bot-email: ${{ secrets.MY_BOT_EMAIL }}