Skip to content

Commit 653c220

Browse files
feat: support configuration files (#99)
* feat: support configuration files * ci: add a test * docs: update README
1 parent 46bafa3 commit 653c220

17 files changed

Lines changed: 877 additions & 82 deletions

File tree

.github/workflows/wc-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ jobs:
2424
- run: go test -v ./... -race -covermode=atomic
2525
- run: go install ./cmd/pinact
2626
- run: pinact -v
27-
- run: pinact run testdata/foo.yaml
28-
- run: git diff
27+
- run: pinact run
28+
- run: diff testdata/foo.yaml testdata/foo.yaml.after

.pinact.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pinact - https://github.com/suzuki-shunsuke/pinact
2+
files:
3+
- pattern: "^\\.github/workflows/.*\\.ya?ml$"
4+
- pattern: "^(.*/)?action\\.ya?ml$"
5+
- pattern: "^testdata/.*\\.ya?ml$"
6+
7+
ignore_actions:
8+
- name: actions/setup-java
9+
- name: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml

README.md

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,62 @@ If no GitHub Access token is passed, pinact calls GitHub REST API without access
100100

101101
## Usage
102102

103-
```console
104-
$ pinact help
105-
NAME:
106-
pinact - Pin GitHub Actions versions. https://github/com/suzuki-shunsuke/pinact
107-
108-
USAGE:
109-
pinact [global options] command [command options] [arguments...]
103+
Please see [USAGE](USAGE.md).
110104

111-
VERSION:
112-
0.1.0 (8ccd55944c83ff1f4d738343c28d4a6109246d06)
105+
## How to use
113106

114-
COMMANDS:
115-
version Show version
116-
run Pin GitHub Actions versions
117-
help, h Shows a list of commands or help for one command
107+
Please run `pinact run` on a Git repository root directory, then files `\.github/workflows/.*\.ya?ml$` are fixed.
118108

119-
GLOBAL OPTIONS:
120-
--log-level value log level [$PINACT_LOG_LEVEL]
121-
--help, -h show help
122-
--version, -v print the version
109+
```console
110+
$ pinact run
123111
```
124112

113+
You can also specify target files by command line arguments.
114+
115+
e.g.
116+
125117
```console
126-
$ pinact help run
127-
NAME:
128-
pinact run - Pin GitHub Actions versions
118+
$ pinact run action.yaml
119+
```
129120

130-
USAGE:
131-
pinact run [command options] [arguments...]
121+
A configuration file is optional, but pinact supports it.
122+
You can create a configuration file by `pinact init`.
132123

133-
DESCRIPTION:
134-
If no argument is passed, pinact searches GitHub Actions workflow files from .github/workflows.
124+
```console
125+
$ pinact init
126+
```
135127

136-
$ pinact run
128+
About the configuration, please see [Configuration](#Configuration).
137129

138-
You can also pass workflow file paths as arguments.
130+
## Configuration
139131

140-
e.g.
132+
pinact supports a configuration file `.pinact.yaml`.
133+
You can also specify the configuration file path by the environment variable `PINACT_CONFIG` or command line option `-c`.
141134

142-
$ pinact run .github/actions/foo/action.yaml .github/actions/bar/action.yaml
135+
.pinact.yaml
143136

137+
e.g.
144138

145-
OPTIONS:
146-
--help, -h show help
139+
```yaml
140+
files:
141+
- pattern: "^\\.github/workflows/.*\\.ya?ml$"
142+
- pattern: "^(.*/)?action\\.ya?ml$"
143+
144+
ignore_actions:
145+
# slsa-framework/slsa-github-generator doesn't support pinning version
146+
# > Invalid ref: 68bad40844440577b33778c9f29077a3388838e9. Expected ref of the form refs/tags/vX.Y.Z
147+
# https://github.com/slsa-framework/slsa-github-generator/issues/722
148+
- name: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml
147149
```
148150

151+
### `files[].pattern`
152+
153+
The regular expression of target files. If files are passed via positional command line arguments, the configuration is ignored.
154+
155+
### `ignore_actions[].name`
156+
157+
Action and reusable workflow names that pinact ignores.
158+
149159
## See also
150160

151161
- [Renovate github-actions Manager - Additional Information](https://docs.renovatebot.com/modules/manager/github-actions/#additional-information)

USAGE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Usage
2+
3+
<!-- This is generated by scripts/generate-usage.sh. Don't edit this file directly. -->
4+
5+
```console
6+
$ pinact help
7+
NAME:
8+
pinact - Pin GitHub Actions versions. https://github/com/suzuki-shunsuke/pinact
9+
10+
USAGE:
11+
pinact [global options] command [command options] [arguments...]
12+
13+
VERSION:
14+
()
15+
16+
COMMANDS:
17+
version Show version
18+
run Pin GitHub Actions versions
19+
init Create .pinact.yaml if it doesn't exist
20+
help, h Shows a list of commands or help for one command
21+
22+
GLOBAL OPTIONS:
23+
--log-level value log level [$PINACT_LOG_LEVEL]
24+
--config value, -c value configuration file path [$PINACT_CONFIG]
25+
--help, -h show help
26+
--version, -v print the version
27+
```
28+
29+
## pinact init
30+
31+
```console
32+
$ pinact help init
33+
NAME:
34+
pinact init - Create .pinact.yaml if it doesn't exist
35+
36+
USAGE:
37+
pinact init [command options] [arguments...]
38+
39+
DESCRIPTION:
40+
Create .pinact.yaml if it doesn't exist
41+
42+
$ pinact init
43+
44+
You can also pass configuration file path.
45+
46+
e.g.
47+
48+
$ pinact init .github/pinact.yaml
49+
50+
51+
OPTIONS:
52+
--help, -h show help
53+
```
54+
55+
## pinact run
56+
57+
```console
58+
$ pinact help run
59+
NAME:
60+
pinact run - Pin GitHub Actions versions
61+
62+
USAGE:
63+
pinact run [command options] [arguments...]
64+
65+
DESCRIPTION:
66+
If no argument is passed, pinact searches GitHub Actions workflow files from .github/workflows.
67+
68+
$ pinact run
69+
70+
You can also pass workflow file paths as arguments.
71+
72+
e.g.
73+
74+
$ pinact run .github/actions/foo/action.yaml .github/actions/bar/action.yaml
75+
76+
77+
OPTIONS:
78+
--help, -h show help
79+
```

cmdx.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ tasks:
4747
usage: Run pinact via go run
4848
script: |
4949
go run ./cmd/pinact {{._builtin.args_string}}
50+
- name: usage
51+
description: Generate USAGE.md
52+
usage: Generate USAGE.md
53+
script: bash scripts/generate-usage.sh

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ require (
66
github.com/google/go-github/v53 v53.2.0
77
github.com/mattn/go-colorable v0.1.13
88
github.com/sirupsen/logrus v1.9.3
9+
github.com/spf13/afero v1.9.5
910
github.com/suzuki-shunsuke/logrus-error v0.1.4
1011
github.com/urfave/cli/v2 v2.25.7
1112
golang.org/x/oauth2 v0.10.0
13+
gopkg.in/yaml.v3 v3.0.1
1214
)
1315

1416
require (
@@ -23,6 +25,7 @@ require (
2325
golang.org/x/crypto v0.11.0 // indirect
2426
golang.org/x/net v0.12.0 // indirect
2527
golang.org/x/sys v0.10.0 // indirect
28+
golang.org/x/text v0.11.0 // indirect
2629
google.golang.org/appengine v1.6.7 // indirect
2730
google.golang.org/protobuf v1.31.0 // indirect
2831
)

0 commit comments

Comments
 (0)