Skip to content

Commit c72fe7c

Browse files
committed
feat(release-please): add config location action
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 87e6ef3 commit c72fe7c

6 files changed

Lines changed: 157 additions & 1 deletion

File tree

‎.github/release-please-config.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"actions/semconv/pull-request": {
2424
"component": "semconv-pull-request",
2525
"initial-version": "0.0.1"
26+
},
27+
"actions/release-please/config": {
28+
"component": "release-please-config",
29+
"initial-version": "0.0.1"
2630
}
2731
},
2832
"plugins": [
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"actions/semconv/pull-request": "0.0.1"
2+
"actions/semconv/pull-request": "0.0.1",
3+
"actions/release-please/config": "0.0.0"
34
}

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ jobs:
2727
- uses: jdx/mise-action@c2a87611a18de5b3828c5652fe268e992400cb5c # v4.3.0
2828

2929
- run: mise run github:actions:ci:lint
30+
31+
# The repository holds itself to the convention it ships.
32+
- uses: ./actions/release-please/config

‎actions/release-please/README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# release-please
2+
3+
Actions that keep [release-please][release-please] set up the same way in every
4+
repository.
5+
6+
| Action | Enforces |
7+
| --- | --- |
8+
| [`config`](config) | Where the configuration and manifest live |
9+
10+
[release-please]: https://github.com/googleapis/release-please
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# release-please/config
2+
3+
Fails a repository whose release-please configuration is not where every
4+
repository keeps it:
5+
6+
```
7+
.github/release-please-config.json
8+
.github/release-please-manifest.json
9+
```
10+
11+
## Usage
12+
13+
The action reads the checked out working tree through `git ls-files`, so it
14+
needs a checkout and nothing else.
15+
16+
```yaml
17+
name: CI
18+
19+
on: pull_request
20+
21+
permissions: {}
22+
23+
jobs:
24+
release-please-config:
25+
name: Validate Release Please Config
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 5
28+
permissions:
29+
contents: read
30+
steps:
31+
- uses: actions/checkout@<full-sha>
32+
with:
33+
persist-credentials: false
34+
- uses: TrogonStack/github-actions/actions/release-please/config@<full-sha>
35+
```
36+
37+
## What it checks
38+
39+
The configuration and the manifest exist at those two paths and parse as JSON.
40+
41+
No other copy is tracked anywhere in the repository. A copy left behind after a
42+
move is worse than never moving, because release-please reads the one the
43+
workflow names and the other rots unnoticed.
44+
45+
Every workflow that runs `release-please-action` passes exactly those two paths
46+
as `config-file` and `manifest-file`. Files in the right place and a workflow
47+
still pointing at the old ones is a repository that has stopped releasing.
48+
49+
A repository that does not use release-please passes without doing anything, so
50+
the action is safe to put in a shared CI workflow.
51+
52+
## Why .github
53+
54+
Both organizations already keep these files in `.github/`, and release-please
55+
never discovers them by convention, the paths are passed explicitly in every
56+
workflow. The location is a house convention, so the only thing worth enforcing
57+
is that it is the same one everywhere.
58+
59+
The leading-dot spelling, `.github/.release-please-config.json`, is rejected on
60+
purpose. The files already sit inside a dot-directory, so the second dot only
61+
hides them from `ls`.
62+
63+
## Inputs
64+
65+
None. One location for every repository is the reason this action exists.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Validate Release Please Config
2+
description: >-
3+
Fails a repository whose release-please configuration is not where every
4+
repository keeps it.
5+
author: TrogonStack
6+
7+
runs:
8+
using: composite
9+
steps:
10+
- name: Validate release-please configuration
11+
shell: bash
12+
run: |
13+
set -euo pipefail
14+
15+
config=.github/release-please-config.json
16+
manifest=.github/release-please-manifest.json
17+
failed=0
18+
19+
fail() {
20+
printf '::error file=%s::%s\n' "$1" "$2"
21+
failed=1
22+
}
23+
24+
# A copy left behind after a move is worse than never moving, because
25+
# release-please reads the one the workflow names and the other rots.
26+
strays=$(git ls-files \
27+
| grep -E '(^|/)\.?release-please-(config|manifest)\.json$' \
28+
| grep -vxF "$config" \
29+
| grep -vxF "$manifest" || true)
30+
31+
workflows=$(git ls-files '.github/workflows/*.yml' '.github/workflows/*.yaml')
32+
releasing=''
33+
for workflow in $workflows; do
34+
if grep -q 'release-please-action' "$workflow"; then
35+
releasing="${releasing} ${workflow}"
36+
fi
37+
done
38+
39+
if [ -z "$releasing" ] && [ -z "$strays" ] && [ ! -f "$config" ] && [ ! -f "$manifest" ]; then
40+
echo "This repository does not use release-please, so there is nothing to place."
41+
exit 0
42+
fi
43+
44+
for file in "$config" "$manifest"; do
45+
if [ ! -f "$file" ]; then
46+
fail "$file" "Missing. Every repository keeps release-please configuration here."
47+
elif ! python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$file" 2>/dev/null; then
48+
fail "$file" "Not valid JSON."
49+
fi
50+
done
51+
52+
for stray in $strays; do
53+
fail "$stray" "Release-please configuration belongs in .github/ only."
54+
done
55+
56+
for workflow in $releasing; do
57+
for pair in "config-file:$config" "manifest-file:$manifest"; do
58+
key=${pair%%:*}
59+
want=${pair#*:}
60+
got=$(grep -E "^[[:space:]]*${key}:" "$workflow" \
61+
| head -1 \
62+
| sed -E "s/^[[:space:]]*${key}:[[:space:]]*//" \
63+
| tr -d "\"'" || true)
64+
65+
if [ -z "$got" ]; then
66+
fail "$workflow" "Does not set ${key}. It must be ${want}."
67+
elif [ "$got" != "$want" ]; then
68+
fail "$workflow" "Sets ${key} to ${got}. It must be ${want}."
69+
fi
70+
done
71+
done
72+
73+
exit "$failed"

0 commit comments

Comments
 (0)