From de617515f81fa505e912c018939704bfcb4b2443 Mon Sep 17 00:00:00 2001 From: Dmytro Soroka Date: Sun, 23 Nov 2025 12:33:19 +0100 Subject: [PATCH 1/2] Skip merging draft pull requests in the merge workflow --- .github/workflows/workflow-merge-pull-requests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/workflow-merge-pull-requests.yml b/.github/workflows/workflow-merge-pull-requests.yml index baa88f8..fa4c09c 100644 --- a/.github/workflows/workflow-merge-pull-requests.yml +++ b/.github/workflows/workflow-merge-pull-requests.yml @@ -109,6 +109,12 @@ jobs: continue fi + is_draft=$(gh pr view "$number" -R "$REPO" --json isDraft --jq '.isDraft') + if [ "$is_draft" = "true" ]; then + echo "Skipping PR #$number because it is a draft." + continue + fi + if [[ "$head_lower" == wip* || "$head_lower" == */wip* ]]; then echo "Skipping PR #$number because head branch is marked WIP ($head)." continue From 754d151a6fe1b4eaf7f00ed915b915c1cca288f8 Mon Sep 17 00:00:00 2001 From: Dmytro Soroka Date: Sun, 23 Nov 2025 12:37:46 +0100 Subject: [PATCH 2/2] Update README to enhance workflow documentation and clarify usage examples --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f5e5bd3..b83f5e1 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,121 @@ # Shared GitHub Workflows -Reusable workflows to plug into other repos via `uses: vinitu-net/github-workflows/.github/workflows/.yml@`. After every merge to `main` this repo auto-tags and publishes a release, so always depend on a version tag, not `@main`. +Reusable workflows to plug into other repos via `uses: vinitu-net/github-workflows/.github/workflows/.yml@`. -## Workflows in this repo +- Always pin to a release tag (auto-created on every merge to `main`); avoid `@main`. +- Each workflow accepts `gh_token`; if omitted it falls back to the built-in `GITHUB_TOKEN`. -### Repo-local (used only here) -- `.github/workflows/auto-merge.yml` — PR CI for this repo: runs `actionlint` on PRs to `main` and auto-merges same-repo PRs after the check passes. -- `.github/workflows/release.yml` — release pipeline for this repo, triggered after the `Auto Merge PRs` workflow completes successfully. It determines the version bump, creates a tag, and publishes a GitHub Release. +## Shared workflows (reusable) -### Reusable (shared) workflows -- `.github/workflows/workflow-determine-version-bump.yml` — picks the semver bump based on branch prefixes (`major/`, `feature*/features*/`, `fix*/fixes*/`) and outputs `version-bump` plus `matching_pr`. When invoked via `workflow_call`, pass the triggering PR payload: `pull-requests: ${{ toJson(github.event.pull_request) }}`. -- `.github/workflows/workflow-merge-pull-requests.yml` — auto-merges PRs into a target branch (skips forks and WIP branches), returns JSON with merged PR metadata. When invoked via `workflow_call`, pass the triggering PR payload: `pull-requests: ${{ toJson(github.event.pull_request) }}`. You can set `merge-method` to `merge` (default), `squash`, or `rebase`. -- `.github/workflows/workflow-create-tag.yml` — bumps the version and creates/pushes a git tag. -- `.github/workflows/workflow-create-release.yml` — creates a GitHub Release for the given tag. +### `workflow-determine-version-bump.yml` +Detects which semver segment to bump for a PR targeting a branch. -## Example usage (in a caller repo) +**Inputs** +- `target-branch` (default `main`): only consider PRs targeting this branch. +- `major-branch-prefixes`, `minor-branch-prefixes`, `patch-branch-prefixes`: comma or newline separated branch prefixes to map to a bump. +- `default` (default `patch`): fallback bump when no prefixes match. +- `pull-requests`: PR payload when calling from `workflow_call` (e.g., `toJson(github.event.pull_request)`). + +**Outputs** +- `version-bump`: `major`, `minor`, or `patch`. +- `matching_pr`: `true` if a PR against `target-branch` was found. + +**Example** +```yaml +jobs: + determine-version: + uses: vinitu-net/github-workflows/.github/workflows/workflow-determine-version-bump.yml@vX.Y.Z + with: + target-branch: main + major-branch-prefixes: major/ + minor-branch-prefixes: | + feature/ + features/ + patch-branch-prefixes: | + fix/ + fixes/ + default: patch + secrets: + gh_token: ${{ secrets.GITHUB_TOKEN }} +``` + +### `workflow-merge-pull-requests.yml` +Auto-merges same-repo PRs into a target branch after checks pass. Skips forks, draft PRs, and branches starting with `wip`. + +**Inputs** +- `target-branch` (default `main`): required base branch to merge into. +- `merge-method` (default `merge`): `merge`, `squash`, or `rebase`. +- `pull-requests`: PR payload for `workflow_call` (e.g., `toJson(github.event.pull_request)`). + +**Outputs** +- `merged`: `true` if at least one PR was merged. +- `merged-prs`: JSON array with `number`, `title`, `author`, `head`. + +**Example** +```yaml +jobs: + merge: + uses: vinitu-net/github-workflows/.github/workflows/workflow-merge-pull-requests.yml@vX.Y.Z + with: + target-branch: main + merge-method: squash + pull-requests: ${{ toJson(github.event.pull_request) }} + secrets: + gh_token: ${{ secrets.GITHUB_TOKEN }} +``` + +### `workflow-create-tag.yml` +Creates and pushes the next semver tag based on the provided bump. + +**Inputs** +- `target-branch` (default `main`): branch to check out before tagging. +- `version-bump` (required): `major`, `minor`, or `patch`. + +**Outputs** +- `new-tag`: tag that was created (e.g., `v1.2.3`). +- `previous-tag`: latest existing tag before the bump. + +**Example** +```yaml +jobs: + create-tag: + uses: vinitu-net/github-workflows/.github/workflows/workflow-create-tag.yml@vX.Y.Z + with: + target-branch: main + version-bump: ${{ needs.determine-version.outputs.version-bump }} + secrets: + gh_token: ${{ secrets.GITHUB_TOKEN }} +``` + +### `workflow-create-release.yml` +Publishes a GitHub Release for a given tag. If `merged-prs` is omitted or empty, it collects merged PRs between `previous-tag` and `tag-name`. + +**Inputs** +- `tag-name` (required): tag to publish. +- `previous-tag` (default `v0.0.0`): used for changelog comparison. +- `merged-prs` (default `[]`): JSON array of merged PR metadata. + +**Example** +```yaml +jobs: + create-release: + uses: vinitu-net/github-workflows/.github/workflows/workflow-create-release.yml@vX.Y.Z + with: + tag-name: ${{ needs.create-tag.outputs.new-tag }} + previous-tag: ${{ needs.create-tag.outputs.previous-tag }} + merged-prs: ${{ needs.merge.outputs.merged-prs }} + secrets: + gh_token: ${{ secrets.GITHUB_TOKEN }} +``` + +### End-to-end usage in a caller repo ```yaml jobs: determine-version: uses: vinitu-net/github-workflows/.github/workflows/workflow-determine-version-bump.yml@vX.Y.Z with: target-branch: main - major-branch-prefixes: | - major/ + major-branch-prefixes: major/ minor-branch-prefixes: | feature/ features/ @@ -37,6 +130,7 @@ jobs: uses: vinitu-net/github-workflows/.github/workflows/workflow-merge-pull-requests.yml@vX.Y.Z with: target-branch: main + pull-requests: ${{ toJson(github.event.pull_request) }} secrets: gh_token: ${{ secrets.GITHUB_TOKEN }} @@ -62,4 +156,6 @@ jobs: gh_token: ${{ secrets.GITHUB_TOKEN }} ``` -Replace `vX.Y.Z` with the latest release tag from this repo. +## Repo-local workflows (used only in this repo) +- `.github/workflows/auto-merge.yml` — PR CI for this repo: runs `actionlint` on PRs to `main` and auto-merges same-repo PRs after checks pass. +- `.github/workflows/release.yml` — release pipeline for this repo, triggered after `Auto Merge PRs`; determines bump, tags, and publishes a release.