Skip to content

Commit 5f50cae

Browse files
committed
fix(prepare-release)!: set proper required permissions to create release config
Signed-off-by: Emilien Escalle <[email protected]>
1 parent d825b90 commit 5f50cae

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

.github/workflows/__prepare-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
release:
1414
uses: ./.github/workflows/prepare-release.yml
1515
permissions:
16-
contents: read
16+
contents: write
1717
pull-requests: write
1818
id-token: write # Needed for getting local workflow actions
1919
with:

.github/workflows/prepare-release.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Reusable workflow that performs release preparation tasks:
3434

3535
### Permissions
3636

37-
- **`contents`**: `read`
37+
- **`contents`**: `write`
3838
- **`id-token`**: `write`
3939
- **`pull-requests`**: `write`
4040

@@ -53,10 +53,13 @@ on:
5353
permissions: {}
5454
jobs:
5555
prepare-release:
56-
uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@642cdb54493d05debdc1394f4bfd7365f82e7bf1 # 0.18.2
56+
uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@d825b90e70e04e0a183ab2af1d77c53f86f141be # fix/prepare-release-permissions
5757
permissions: {}
5858
secrets:
59-
# GitHub token with permissions `contents: write`, `pull-requests: write`.
59+
# GitHub token with following permissions:
60+
#
61+
# - `contents: write`
62+
# - `pull-requests: write`
6063
github-token: ""
6164

6265
# GitHub App private key to generate GitHub token in place of github-token.
@@ -113,7 +116,10 @@ jobs:
113116

114117
| **Secret** | **Description** | **Required** |
115118
| -------------------- | ------------------------------------------------------------------------- | ------------ |
116-
| **`github-token`** | GitHub token with permissions `contents: write`, `pull-requests: write`. | **false** |
119+
| **`github-token`** | GitHub token with following permissions: | **false** |
120+
| | | |
121+
| | - `contents: write` | |
122+
| | - `pull-requests: write` | |
117123
| **`github-app-key`** | GitHub App private key to generate GitHub token in place of github-token. | **false** |
118124
| | See <https://github.com/actions/create-github-app-token>. | |
119125

@@ -141,7 +147,7 @@ permissions: {}
141147
142148
jobs:
143149
prepare-release:
144-
uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@642cdb54493d05debdc1394f4bfd7365f82e7bf1 # 0.18.2
150+
uses: hoverkraft-tech/ci-github-publish/.github/workflows/prepare-release.yml@d825b90e70e04e0a183ab2af1d77c53f86f141be # fix/prepare-release-permissions
145151
permissions:
146152
contents: read
147153
pull-requests: write

.github/workflows/prepare-release.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ on:
3939
secrets:
4040
github-token:
4141
description: |
42-
GitHub token with permissions `contents: write`, `pull-requests: write`.
42+
GitHub token with following permissions:
43+
44+
- `contents: write`
45+
- `pull-requests: write`
4346
github-app-key:
4447
description: |
4548
GitHub App private key to generate GitHub token in place of github-token.
@@ -101,7 +104,7 @@ jobs:
101104
const configPath = process.env.CONFIG_PATH;
102105
if (!configPath){
103106
return core.setFailed('Configuration path is not specified.');
104-
}
107+
}
105108
if (!fs.existsSync(configPath)) {
106109
return core.warning(`Release configuration file "${configPath}" does not exist.`);
107110
}
@@ -137,7 +140,7 @@ jobs:
137140
if: github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
138141
runs-on: ${{ fromJson(inputs.runs-on) }}
139142
permissions:
140-
contents: read
143+
contents: write
141144
pull-requests: write
142145
env:
143146
INCLUDE_PATHS: ${{ inputs.include-paths }}
@@ -190,7 +193,7 @@ jobs:
190193
}
191194
}
192195
193-
// Build include-paths section if includePaths is not empty
196+
// Build include-paths section if includePaths is not empty
194197
let includePathsSection = '';
195198
if (includePaths.size > 0 ) {
196199
const pathsYaml = Array.from(includePaths).map(p => ` - "${p}"`).join('\n');
@@ -280,24 +283,24 @@ jobs:
280283
script: |
281284
const fs = require('node:fs');
282285
const path = require('node:path');
286+
283287
const configContent = process.env.CONFIG_CONTENT;
284288
const configPath = process.env.CONFIG_PATH;
285289
const configDir = path.dirname(configPath);
290+
286291
fs.mkdirSync(configDir, { recursive: true });
287292
fs.writeFileSync(configPath, configContent, 'utf8');
288293
289-
core.setOutput('branch', `ci/prepare-release-config${
290-
process.env.CONFIG_SLUG ? `/${process.env.CONFIG_SLUG}` : ''
291-
}`);
292-
core.setOutput('title', `ci: prepare release configuration${
293-
process.env.CONFIG_SLUG ? ` for "${process.env.CONFIG_SLUG}"` : ''
294-
}`);
295-
core.setOutput('body', `Prepare release configuration${
296-
process.env.WORKING_DIRECTORY ? ` for "${process.env.WORKING_DIRECTORY}" working directory` : ''
297-
}.`);
298-
core.setOutput('commit-message', `ci: prepare release configuration${
299-
process.env.CONFIG_SLUG ? ` for "${process.env.CONFIG_SLUG}"` : ''
300-
}\n\n[skip ci]`);
294+
const outputs = {
295+
branch: `ci/prepare-release-config${process.env.CONFIG_SLUG ? `/${process.env.CONFIG_SLUG}` : ''}`,
296+
title: `ci: prepare release configuration${process.env.CONFIG_SLUG ? ` for "${process.env.CONFIG_SLUG}"` : ''}`,
297+
body: `Prepare release configuration${process.env.WORKING_DIRECTORY ? ` for "${process.env.WORKING_DIRECTORY}" working directory` : ''}.`,
298+
"commit-message": `ci: prepare release configuration${process.env.CONFIG_SLUG ? ` for "${process.env.CONFIG_SLUG}"` : ''}\n\n[skip ci]`,
299+
};
300+
301+
for (const [key, value] of Object.entries(outputs)) {
302+
core.setOutput(key, value);
303+
}
301304
302305
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
303306
if: ${{ steps.get-config.outputs.config-content && inputs.github-app-id }}

0 commit comments

Comments
 (0)