Skip to content
Open
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
96 changes: 96 additions & 0 deletions actions/changed-modules-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# changed-modules-go

A GitHub Action that determines which Go modules have changed for a given GitHub
event. It can be used to trigger workflows only for affected modules in
monorepos or multi-module Go projects.

## Features

- Detects which Go modules have changed between commits or pull requests.
- Supports flexible glob patterns for filtering files and module paths.
- Provides outputs in both CSV and JSON formats for easy downstream usage.
- Handles edge cases like scheduled or manually triggered workflows gracefully.

## Inputs

| Name | Description | Required | Default |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- | ----------------------------- |
| `repository-root` | The path to the root of the checked out repository. | ❌ | `${{ github.workspace }}` |
| `file-patterns` | A comma or newline-separated list of glob patterns to include when determining changed modules. Only files matching these patterns are considered. Supports negations (e.g. `!**/*_test.go`). | ❌ | `**/*.go,**/go.mod,**/go.sum` |
| `module-patterns` | A comma or newline-separated list of glob patterns to match module paths to include. Supports negations (e.g. `!**/test/**`). | ❌ | `**` |
| `no-change-behaviour` | Defines what happens when the event has no changeset (e.g. `schedule`, `workflow_dispatch`). Options:<br> - `all`: All modules considered changed.<br> - `root`: Only the root module (`.`).<br> - `latest-commit`: Modules changed in the latest commit.<br> - `none`: No modules considered changed. | ❌ | `all` |

---

## 📤 Outputs

| Name | Description |
| -------------- | --------------------------------------------------------------------------------------------- |
| `modules-csv` | A comma-separated list of changed Go module paths, relative to the current working directory. |
| `modules-json` | A JSON array of changed Go module paths, relative to the current working directory. |

## Example Usage

Here is an example that runs a matrix on changed modules only.

```yaml
name: example

on:
merge_group:
pull_request:
push:
workflow_dispatch:

init:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
outputs:
changed-modules: ${{ steps.changed-modules.outputs.modules-json }}
steps:
- name: Checkout repo (needed to reference local action)
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Changed modules
id: changed-modules
uses: smartcontractkit/.github/actions/changed-modules-go@<tag>
with:
no-change-behaviour: all
file-patterns: |
**/*.go
**/go.mod
**/go.sum
module-patterns: |
**
!path/to/ignore/**

lint:
name: Lint ${{ matrix.modules }}
needs: [ init ]
runs-on: ubuntu-latest

name: GolangCI Lint
permissions:
...
strategy:
fail-fast: false
matrix:
modules: ${{ fromJson(needs.init.outputs.changed-modules) }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
persist-credentials: false

- name: Lint
id: golang-lint
uses: smartcontractkit/.github/actions/ci-lint-go@<tag>
timeout-minutes: 20
with:
go-directory: ${{ matrix.modules }}
only-new-issues: true
```
57 changes: 57 additions & 0 deletions actions/changed-modules-go/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: changed-modules-go
description: "Gets the go modules changed for a github event"

inputs:
github-token:
description: "GitHub token to use for authentication"
default: ${{ github.token }}
required: true

repository-root:
description:
"The root directory of the repository to analyze. It must be the
repository executing this action."
default: ${{ github.workspace }}
required: true

file-patterns:
description: |
A list of glob patterns that specify which files to consider when detecting changed modules.
Supports standard glob syntax, including negations (e.g. `!**/*_test.go` to exclude test files).
Patterns can be separated by commas or newlines.
Relative to the repository root.
required: false
default: "**/*.go,**/go.mod,**/go.sum"

module-patterns:
description: |
A list of glob patterns that specify which Go modules to include when determining changes.
Supports negations (e.g. `!**/test/**` to exclude test modules).
Patterns can be separated by commas or newlines.
Relative to the repository root.
required: false
default: "**"

no-change-behaviour:
description: |
Defines how the action behaves when the triggering event has no associated changeset
(e.g. `schedule`, `workflow_dispatch`).
Available options:
- `all`: Treat all modules as changed.
- `root`: Treat only the root module (`.`) as changed.
- `latest-commit`: Use modules changed in the latest commit.
- `none`: Treat no modules as changed.
required: false
default: "all"

outputs:
modules-csv:
description: |
A CSV string of the paths to the go modules, relative to the repository root.
modules-json:
description: |
A JSON array of the paths to the go modules, relative to the repository root.

runs:
using: "node20"
main: "dist/index.js"
Loading
Loading