Skip to content

Commit e893344

Browse files
authored
GitHub token is required (#4)
2 parents 4e9211b + 03c7226 commit e893344

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ steps:
1212
uses: cloudnode-pro/[email protected]
1313
with:
1414
# See the ‘Inputs’ section below for details.
15+
gh-token: ${{ github.token }}
1516
release-id: 123456 # Optional for `release` events.
1617
files: |
1718
path/to/file.txt; type=text/plain; name=File1.txt
@@ -20,6 +21,14 @@ steps:
2021
2122
## Inputs
2223
24+
### `gh-token`
25+
26+
The GitHub token to use for authentication.
27+
28+
If you are uploading to a release in the same repository, you can use `${{github.token}}`, which is a secret
29+
generated by the workflow. Otherwise, you need to manually create a token, save it as a repository secret, and pass it
30+
using `${{secrets.NAME_OF_SECRET}}`.
31+
2332
### `release-id`
2433

2534
The ID of the release to which to upload files.

action.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Release Upload Asset
22
description: Upload files to a GitHub release
33
inputs:
4+
gh-token:
5+
description: The GitHub token to use for authentication.
6+
required: true
47
release-id:
58
description: The ID of the release to which to upload files.
69
required: false

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ function parseInputFileParams(input: string): {path: string, params: Record<stri
2424

2525
// Action inputs
2626
const GH_INPUTS: Record<string, string> = JSON.parse(process.env.GH_INPUTS!);
27-
const GITHUB_TOKEN = process.env.GITHUB_TOKEN!;
2827

2928
const inputs = {
29+
ghToken: GH_INPUTS["gh-token"]!,
3030
releaseId: GH_INPUTS["release-id"]!,
3131
files: GH_INPUTS["files"]!,
3232
};
@@ -60,7 +60,7 @@ const files = (await Promise.all(inputs.files.split("\n").map(async f => {
6060
}))).filter(f => f !== null);
6161

6262
// Upload the files
63-
const octokit = github.getOctokit(GITHUB_TOKEN);
63+
const octokit = github.getOctokit(inputs.ghToken);
6464
core.info("Getting release...");
6565
const release = await octokit.rest.repos.getRelease({
6666
owner: github.context.repo.owner,
@@ -75,7 +75,7 @@ const responses = await Promise.all(
7575
const res = await fetch(parseUriTemplate(release.data.upload_url).expand({name: file.name}), {
7676
method: "POST",
7777
headers: {
78-
"Authorization": "token " + GITHUB_TOKEN,
78+
"Authorization": "token " + inputs.ghToken,
7979
},
8080
body: file
8181
});

0 commit comments

Comments
 (0)