Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/workflow-merge-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
124 changes: 110 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,121 @@
# Shared GitHub Workflows

Reusable workflows to plug into other repos via `uses: vinitu-net/github-workflows/.github/workflows/<workflow>.yml@<tag>`. 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/<workflow>.yml@<tag>`.

## 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/
Expand All @@ -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 }}

Expand All @@ -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.