Compare commits
229 Commits
v1-release
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
84f3aed823 | ||
|
f9770cdf31 | ||
|
1b2bf5c959 | ||
|
265508bc9f | ||
|
04733e069f | ||
|
7b5b755e5b | ||
|
17449a21ea | ||
|
ec2ff03a5a | ||
|
ff23fb2574 | ||
|
8e438350b0 | ||
|
fe68892921 | ||
|
a13e7b5d40 | ||
|
a4bae284e7 | ||
|
c19ddf4c20 | ||
|
2d9c0f4337 | ||
|
615015f76e | ||
|
e3374ce5b6 | ||
|
1beeb572c1 | ||
|
5206d34958 | ||
|
80d7a7e41c | ||
|
5eb2ffd70b | ||
|
07af2f374a | ||
|
5164410c7d | ||
|
f47fb36ff1 | ||
|
212d4babf8 | ||
|
7670b98fa0 | ||
|
ac438791c4 | ||
|
545e4c402b | ||
|
7d304ee154 | ||
|
3cff01dd32 | ||
|
a724093295 | ||
|
2b9d2847a9 | ||
|
f9beb0ad08 | ||
|
1662cfa449 | ||
|
a5002416a0 | ||
|
58d5258088 | ||
|
ffc1afa9c0 | ||
|
24bced81d9 | ||
|
794b3152e1 | ||
|
b00963776a | ||
|
210500d479 | ||
|
f0dfba8919 | ||
|
42c63808d6 | ||
|
febd7d0808 | ||
|
d8e2a64134 | ||
|
a4af572b12 | ||
|
7d4e20c14b | ||
|
7e467024cd | ||
|
e225e77501 | ||
|
6295ff030e | ||
|
37a32b0167 | ||
|
0c6fec2cea | ||
|
37f4f3a9cd | ||
|
dfae8c036c | ||
|
99e2100a1f | ||
|
664a7c20c1 | ||
|
760a5584dc | ||
|
580065490f | ||
|
eed453b613 | ||
|
7319e4733e | ||
|
4e86b8565b | ||
|
3a6baf0f12 | ||
|
e8c797e08e | ||
|
cf83be2c7f | ||
|
cfdd9b50bd | ||
|
cc92c9093e | ||
|
72f6bf584a | ||
|
f2899b4677 | ||
|
af306bddfe | ||
|
9927d3f5ec | ||
|
e5e4b800aa | ||
|
74f6bde645 | ||
|
0e6c75888a | ||
|
5cbce4f5ee | ||
|
df11ebfac2 | ||
|
50a5b0990c | ||
|
0e0bd99213 | ||
|
8250434419 | ||
|
9093186278 | ||
|
321f000b6d | ||
|
233ab9a35e | ||
|
d3a6c14a79 | ||
|
fa5d5d5a33 | ||
|
442eb645ce | ||
|
4d1e10f6d1 | ||
|
f63a22975a | ||
|
a9842f0f62 | ||
|
2728235f7d | ||
|
c2e0608dc4 | ||
|
bd74772a1a | ||
|
16e7903b2d | ||
|
f2c549b117 | ||
|
7a7d004438 | ||
|
9c4a92ec0d | ||
|
039214a996 | ||
|
2b373356cb | ||
|
1819382cf9 | ||
|
fb1eb39e74 | ||
|
7786b24bd8 | ||
|
133984371c | ||
|
c2b649c57e | ||
|
eb625cd0ad | ||
|
99cbd251b2 | ||
|
a6824c9e54 | ||
|
6eb74c809d | ||
|
8ec375d911 | ||
|
8d45355ac2 | ||
|
7d269bd712 | ||
|
c71fb95114 | ||
|
1d71c233f7 | ||
|
78ec101a88 | ||
|
d8cafc3c87 | ||
|
a70d06e688 | ||
|
072f986a7c | ||
|
2f88c7710e | ||
|
ee200cfabc | ||
|
82b6f4a2ea | ||
|
3f585610ac | ||
|
61a0748878 | ||
|
743e8a90bd | ||
|
15ebdecb60 | ||
|
57649ec774 | ||
|
f9dffdf5a6 | ||
|
71756ac6ec | ||
|
2b6c678b07 | ||
|
a95c4e7c33 | ||
|
4e5de20777 | ||
|
3f38d56a41 | ||
|
483c1e56f9 | ||
|
1899a6bd0d | ||
|
bf76499b98 | ||
|
e74ff71f7d | ||
|
697a9f190e | ||
|
011f7957ff | ||
|
4f71b6d30b | ||
|
24b1cacbb1 | ||
|
4ce0a13e83 | ||
|
6ca3eb1422 | ||
|
54a6699008 | ||
|
afb12c9a16 | ||
|
89767936cf | ||
|
d3d2e8da76 | ||
|
ec0ba8651f | ||
|
0d3c327d15 | ||
|
24dc1f0ef1 | ||
|
94502fe175 | ||
|
2f92806c5d | ||
|
d715678c11 | ||
|
3735b5ec52 | ||
|
17fcb1df4f | ||
|
47b74e816a | ||
|
a9a904a8a4 | ||
|
49404e33ce | ||
|
c5cd3d711a | ||
|
f58e245343 | ||
|
1daf68639d | ||
|
3c84140b3e | ||
|
fa9b523f3c | ||
|
6bb16de6db | ||
|
adacb86abb | ||
|
fbd30418aa | ||
|
588487bf09 | ||
|
c0f4101399 | ||
|
30dfbfdd8d | ||
|
806b0b0631 | ||
|
fdd8502475 | ||
|
8277eef782 | ||
|
fbc34f818a | ||
|
38c90ed08f | ||
|
c7fa458e37 | ||
|
8c679d7487 | ||
|
7cac809eef | ||
|
d082cf3f16 | ||
|
9afb63d9be | ||
|
0c20962e0b | ||
|
bd83be724b | ||
|
5788568237 | ||
|
05bca815fe | ||
|
0faf394792 | ||
|
826b119adc | ||
|
c48071c5e8 | ||
|
ba09d617a8 | ||
|
c14556ae27 | ||
|
efda0e7412 | ||
|
3e5b1a7442 | ||
|
5d5ed153e8 | ||
|
d151157326 | ||
|
d59b001b39 | ||
|
802e00067c | ||
|
ffdc680f33 | ||
|
48ee6952fb | ||
|
319155ea78 | ||
|
ef27273521 | ||
|
41ca44be6f | ||
|
7238d4307d | ||
|
003f46c67a | ||
|
d49eb2564a | ||
|
179efc987d | ||
|
6dd75691d6 | ||
|
8f6457b46e | ||
|
842807fcaf | ||
|
e6466806bd | ||
|
623a8a1785 | ||
|
96917a90ee | ||
|
95b7f6102f | ||
|
ff946c0b57 | ||
|
646b122c81 | ||
|
907e5dae80 | ||
|
d69dec835b | ||
|
0e699b142b | ||
|
010fda07b6 | ||
|
0f446d9646 | ||
|
d7e47607f7 | ||
|
bf98c4413f | ||
|
12f7fc1a8b | ||
|
08e809b7ae | ||
|
371a3bf0be | ||
|
f4d050cb90 | ||
|
b8902a20c8 | ||
|
5f836e8716 | ||
|
223b39fc7a | ||
|
c571424387 | ||
|
a09c67074f | ||
|
11f6e3b5af | ||
|
1d082de854 | ||
|
387cfa6016 | ||
|
aa32ea81b6 | ||
|
48b3121e13 | ||
|
55755cd0bc |
3
.eslintignore
Normal file
3
.eslintignore
Normal file
@ -0,0 +1,3 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
55
.eslintrc.json
Normal file
55
.eslintrc.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"plugins": ["jest", "@typescript-eslint", "github"],
|
||||
"extends": ["plugin:github/typescript"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {
|
||||
"accessibility": "no-public"
|
||||
}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {
|
||||
"allowExpressions": true
|
||||
}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
||||
github: svenstaro
|
25
.github/workflows/checkin.yml
vendored
25
.github/workflows/checkin.yml
vendored
@ -1,25 +0,0 @@
|
||||
name: "PR Checks"
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
check_pr:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
- name: "npm ci"
|
||||
run: npm ci
|
||||
|
||||
- name: "npm run build"
|
||||
run: npm run build
|
||||
|
||||
- name: "npm run test"
|
||||
run: npm run test
|
||||
|
||||
- name: "check for uncommitted changes"
|
||||
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
|
||||
run: |
|
||||
git diff --exit-code --stat -- . ':!node_modules' \
|
||||
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
|
||||
"and check in all changes" \
|
||||
&& exit 1)
|
102
.github/workflows/ci.yml
vendored
Normal file
102
.github/workflows/ci.yml
vendored
Normal file
@ -0,0 +1,102 @@
|
||||
name: "CI"
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build: # make sure build/ci work properly
|
||||
name: CI on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
|
||||
test: # make sure the action works on a clean machine without building
|
||||
name: E2E test
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Make test pre-release
|
||||
uses: ./
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: README.md
|
||||
asset_name: TEST.md
|
||||
tag: ci-test-${{ matrix.os }}-${{ github.run_id }}
|
||||
overwrite: true
|
||||
prerelease: true
|
||||
make_latest: true
|
||||
body: "rofl lol test%0Aianal %25 fubar"
|
||||
- name: Check that the uploaded asset is readable
|
||||
uses: actions/github-script@v2
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const fs = require('fs')
|
||||
const assert = require('assert').strict;
|
||||
|
||||
const expected = fs.readFileSync("README.md", "utf-8")
|
||||
const release = await github.repos.getReleaseByTag({
|
||||
...context.repo,
|
||||
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
||||
})
|
||||
assert.deepStrictEqual(release.data.prerelease, true)
|
||||
assert.deepStrictEqual(release.data.body, "rofl lol test\nianal % fubar")
|
||||
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
|
||||
const actual = await github.request(release.data.assets[0].browser_download_url)
|
||||
assert.deepStrictEqual(expected, actual.data)
|
||||
- name: Make test promote
|
||||
uses: ./
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: README.md
|
||||
asset_name: TEST.md
|
||||
tag: ci-test-${{ matrix.os }}-${{ github.run_id }}
|
||||
overwrite: true
|
||||
promote: true
|
||||
prerelease: false
|
||||
make_latest: true
|
||||
body: "new body"
|
||||
- name: Check that the release is promoted
|
||||
uses: actions/github-script@v2
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
retries: 15
|
||||
script: |
|
||||
const fs = require('fs')
|
||||
const assert = require('assert').strict;
|
||||
|
||||
const expected = fs.readFileSync("README.md", "utf-8")
|
||||
const release = await github.repos.getReleaseByTag({
|
||||
...context.repo,
|
||||
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
||||
})
|
||||
assert.deepStrictEqual(release.data.prerelease, false)
|
||||
assert.deepStrictEqual(release.data.body, "new body")
|
||||
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
|
||||
const actual = await github.request(release.data.assets[0].browser_download_url)
|
||||
assert.deepStrictEqual(expected, actual.data)
|
||||
- name: Clean up
|
||||
if: ${{ always() }}
|
||||
uses: actions/github-script@v2
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
script: |
|
||||
const release = await github.repos.getReleaseByTag({
|
||||
...context.repo,
|
||||
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
||||
})
|
||||
await github.repos.deleteRelease({
|
||||
...context.repo,
|
||||
release_id: release.data.id,
|
||||
})
|
||||
await github.git.deleteRef({
|
||||
...context.repo,
|
||||
ref: "tags/ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
||||
})
|
15
.github/workflows/versioning.yml
vendored
Normal file
15
.github/workflows/versioning.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
name: Keep the versions up-to-date
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published, edited]
|
||||
|
||||
jobs:
|
||||
actions-tagger:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: Actions-R-Us/actions-tagger@latest
|
||||
env:
|
||||
GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}"
|
||||
with:
|
||||
publish_latest_tag: true
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
node_modules/
|
||||
__tests__/runner/*
|
||||
node_modules
|
||||
run.sh
|
||||
__tests__/runner/*
|
||||
lib/**/*
|
||||
.idea
|
||||
|
3
.prettierignore
Normal file
3
.prettierignore
Normal file
@ -0,0 +1,3 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 80,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"semi": false,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": false,
|
||||
"arrowParens": "avoid",
|
||||
"parser": "typescript"
|
||||
}
|
54
CHANGELOG.md
Normal file
54
CHANGELOG.md
Normal file
@ -0,0 +1,54 @@
|
||||
# Changelog
|
||||
|
||||
## [2.9.0] - 2024-02-22
|
||||
- Allow seeting a release as draft [#112](https://github.com/svenstaro/upload-release-action/pull/112) (thanks @ShonP40)
|
||||
|
||||
## [2.8.0] - 2024-02-21
|
||||
- Bump all deps
|
||||
- Update to node 20
|
||||
|
||||
## [2.7.0] - 2023-07-28
|
||||
- Allow setting an explicit target_commitish [#46](https://github.com/svenstaro/upload-release-action/pull/46) (thanks @Spikatrix)
|
||||
|
||||
## [2.6.1] - 2023-05-31
|
||||
- Do not overwrite body or name if empty [#108](https://github.com/svenstaro/upload-release-action/pull/108) (thanks @regevbr)
|
||||
|
||||
## [2.6.0] - 2023-05-23
|
||||
- Add `make_latest` input parameter. Can be set to `false` to prevent the created release from being marked as the latest release for the repository [#100](https://github.com/svenstaro/upload-release-action/pull/100) (thanks @brandonkelly)
|
||||
- Don't try to upload empty files [#102](https://github.com/svenstaro/upload-release-action/pull/102) (thanks @Loyalsoldier)
|
||||
- Bump all deps [#105](https://github.com/svenstaro/upload-release-action/pull/105)
|
||||
- `overwrite` option also overwrites name and body [#106](https://github.com/svenstaro/upload-release-action/pull/106) (thanks @regevbr)
|
||||
- Add `promote` option to allow prereleases to be promoted [#74](https://github.com/svenstaro/upload-release-action/pull/74) (thanks @regevbr)
|
||||
|
||||
## [2.5.0] - 2023-02-21
|
||||
- Add retry to upload release [#96](https://github.com/svenstaro/upload-release-action/pull/96) (thanks @sonphantrung)
|
||||
|
||||
## [2.4.1] - 2023-02-01
|
||||
- Modernize octokit usage
|
||||
|
||||
## [2.4.0] - 2023-01-09
|
||||
- Update to node 16
|
||||
- Bump most dependencies
|
||||
|
||||
## [2.3.0] - 2022-06-05
|
||||
- Now defaults `repo_token` to `${{ github.token }}` and `tag` to `${{ github.ref }}` [#69](https://github.com/svenstaro/upload-release-action/pull/69) (thanks @leighmcculloch)
|
||||
|
||||
## [2.2.1] - 2020-12-16
|
||||
- Added support for the GitHub pagination API for repositories with many releases [#36](https://github.com/svenstaro/upload-release-action/pull/36) (thanks @djpohly)
|
||||
|
||||
## [2.2.0] - 2020-10-07
|
||||
- Add support for ceating a new release in a foreign repository [#25](https://github.com/svenstaro/upload-release-action/pull/25) (thanks @kittaakos)
|
||||
- Upgrade all deps
|
||||
|
||||
## [2.1.1] - 2020-09-25
|
||||
- Fix `release_name` option [#27](https://github.com/svenstaro/upload-release-action/pull/27) (thanks @kittaakos)
|
||||
|
||||
## [2.1.0] - 2020-08-10
|
||||
- Strip refs/heads/ from the input tag [#23](https://github.com/svenstaro/upload-release-action/pull/23) (thanks @OmarEmaraDev)
|
||||
|
||||
## [2.0.0] - 2020-07-03
|
||||
- Add `prerelease` input parameter. Setting this marks the created release as a pre-release.
|
||||
- Add `release_name` input parameter. Setting this explicitly sets the title of the release.
|
||||
- Add `body` input parameter. Setting this sets the text content of the created release.
|
||||
- Add `browser_download_url` output variable. This contains the publicly accessible download URL of the uploaded artifact.
|
||||
- Allow for leaving `asset_name` unset. This will cause the asset to use the filename.
|
152
README.md
152
README.md
@ -1,4 +1,4 @@
|
||||
# Upload files to a GitHub release [](https://github.com/svenstaro/upload-release-action/actions)
|
||||
# Upload files to a GitHub release [](https://github.com/svenstaro/upload-release-action/actions)
|
||||
|
||||
This action allows you to select which files to upload to the just-tagged release.
|
||||
It runs on all operating systems types offered by GitHub.
|
||||
@ -7,15 +7,28 @@ It runs on all operating systems types offered by GitHub.
|
||||
|
||||
You must provide:
|
||||
|
||||
- `repo_token`: Usually you'll want to set this to `${{ secrets.GITHUB_TOKEN }}`
|
||||
- `file`: A local file to be uploaded as the asset.
|
||||
- `asset_name`: The name the file gets as an asset on a release.
|
||||
- `tag`: The tag to uploaded into. If you want the current event's tag, use `${{ github.ref }}`
|
||||
- `overwrite`: If an asset with the same name already exists, overwrite it.
|
||||
|
||||
Optional Arguments
|
||||
|
||||
- `file_glob`: If set to true, the file argument can be a glob pattern (`asset_name` is ignored in this case)
|
||||
- `repo_token`: Defaults to `github.token`.
|
||||
- `tag`: The tag to upload into. If you want the current event's tag or branch name, use `${{ github.ref }}` (the `refs/tags/` and `refs/heads/` prefixes will be automatically stripped). Defaults to `github.ref`.
|
||||
- `asset_name`: The name the file gets as an asset on a release. Use `$tag` to include the tag name. When not provided it will default to the filename.
|
||||
This is not used if `file_glob` is set to `true`.
|
||||
- `file_glob`: If set to true, the `file` argument can be a glob pattern (`asset_name` is ignored in this case) (Default: `false`)
|
||||
- `overwrite`: If an asset with the same name already exists, overwrite it (Default: `false`).
|
||||
- `promote`: If a prerelease already exists, promote it to a release (Default: `false`).
|
||||
- `draft`: Sets the release as a draft instead of publishing it, allowing you to make any edits needed before releasing (Default: `false`).
|
||||
- `prerelease`: Mark the release as a pre-release (Default: `false`).
|
||||
- `make_latest`: Mark the release as the latest release for the repository (Default: `true`).
|
||||
- `release_name`: Explicitly set a release name. (Defaults: implicitly same as `tag` via GitHub API).
|
||||
- `target_commit`: Sets the commit hash or branch for the tag to be based on (Default: the default branch, usually `main`).
|
||||
- `body`: Content of the release text (Default: `""`).
|
||||
- `repo_name`: Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. (Default: current repository).
|
||||
|
||||
## Output variables
|
||||
|
||||
- `browser_download_url`: The publicly available URL of the asset.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -38,20 +51,18 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: hecrj/setup-rust-action@v1-release
|
||||
with:
|
||||
rust-version: stable
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --release
|
||||
- name: Upload binaries to release
|
||||
uses: svenstaro/upload-release-action@v1-release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: target/release/mything
|
||||
asset_name: mything
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
body: "This is my release text"
|
||||
```
|
||||
|
||||
Complex example with more operating systems:
|
||||
@ -82,14 +93,11 @@ jobs:
|
||||
asset_name: mything-macos-amd64
|
||||
|
||||
steps:
|
||||
- uses: hecrj/setup-rust-action@v1-release
|
||||
with:
|
||||
rust-version: stable
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --release --locked
|
||||
- name: Upload binaries to release
|
||||
uses: svenstaro/upload-release-action@v1-release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: target/release/${{ matrix.artifact_name }}
|
||||
@ -98,29 +106,129 @@ jobs:
|
||||
```
|
||||
|
||||
Example with `file_glob`:
|
||||
|
||||
```yaml
|
||||
name: Publish
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Publish binaries
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: hecrj/setup-rust-action@v1-release
|
||||
with:
|
||||
rust-version: stable
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --release
|
||||
- name: Upload binaries to release
|
||||
uses: svenstaro/upload-release-action@v1-release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: target/release/my*
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
file_glob: true
|
||||
```
|
||||
```
|
||||
|
||||
Example for creating a release in a foreign repository using `repo_name`:
|
||||
|
||||
```yaml
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Publish binaries
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Build
|
||||
run: cargo build --release
|
||||
- name: Upload binaries to release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_name: owner/repository-name
|
||||
# A personal access token for the GitHub repository in which the release will be created and edited.
|
||||
# It is recommended to create the access token with the following scopes: `repo, user, admin:repo_hook`.
|
||||
repo_token: ${{ secrets.YOUR_PERSONAL_ACCESS_TOKEN }}
|
||||
file: target/release/mything
|
||||
asset_name: mything
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: true
|
||||
body: "This is my release text"
|
||||
```
|
||||
|
||||
**Example for feeding a file from repo to the `body` tag:**
|
||||
|
||||
This example covers following points:
|
||||
* Reading a file present on the repo. For example, `release.md` which is placed in root directory of the repo.
|
||||
* Modify & push the `release.md` file before triggering this action (create tag for this example) to dynamically change the body of the release.
|
||||
|
||||
```yaml
|
||||
name: Publish
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
name: Publish binaries
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# This step reads a file from repo and use it for body of the release
|
||||
# This works on any self-hosted runner OS
|
||||
- name: Read release.md and use it as a body of new release
|
||||
id: read_release
|
||||
shell: bash
|
||||
run: |
|
||||
r=$(cat path/to/release.md) # <--- Read release.md (Provide correct path as per your repo)
|
||||
r="${r//'%'/'%25'}" # Multiline escape sequences for %
|
||||
r="${r//$'\n'/'%0A'}" # Multiline escape sequences for '\n'
|
||||
r="${r//$'\r'/'%0D'}" # Multiline escape sequences for '\r'
|
||||
echo "RELEASE_BODY=$r" >> $GITHUB_OUTPUT # <--- Set environment variable
|
||||
|
||||
- name: Upload Binaries to Release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
tag: ${{ github.ref }}
|
||||
body: |
|
||||
${{ steps.read_release.outputs.RELEASE_BODY }} # <--- Use environment variables that was created earlier
|
||||
|
||||
```
|
||||
|
||||
### Permissions
|
||||
|
||||
This actions requires writes access to the release. If you are using [granular permissions](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions)
|
||||
in your workflow, you will need to add the `contents: write` permission to the token:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
contents: write
|
||||
```
|
||||
|
||||
## Releasing
|
||||
|
||||
To release this Action:
|
||||
|
||||
- Bump version in `package.json`
|
||||
- Create `CHANGELOG.md` entry
|
||||
- `npm update`
|
||||
- `npm run all`
|
||||
- `git commit -am <version>`
|
||||
- `git tag -sm <version> <version>`
|
||||
- `git push --follow-tags`
|
||||
- Go to https://github.com/svenstaro/upload-release-action/releases and publish the new version
|
||||
|
@ -1,6 +1,25 @@
|
||||
import * as main from '../src/main';
|
||||
import * as github from '@actions/github'
|
||||
import * as main from '../src/main'
|
||||
|
||||
// Frankly, tests would be entirely useless unless we can mock GitHub somehow.
|
||||
describe('Upload Release Action', () => {
|
||||
it('', async () => {});
|
||||
});
|
||||
let spyGetOctokit: jest.SpyInstance<any>
|
||||
let mockOctokit: any
|
||||
|
||||
beforeEach(() => {
|
||||
mockOctokit = {
|
||||
repos: {
|
||||
createRelease: jest.fn(async () => ({
|
||||
data: {
|
||||
id: 'lalala',
|
||||
upload_url: 'oaoa'
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
// spyGetOctokit = jest.spyOn(github, "getOctokit").mockImplementation(() => mockOctokit
|
||||
// jest.spyOn(github, "context", "get").mockImplementation(() => "testtest");
|
||||
})
|
||||
|
||||
it('pls write actual test', async () => {})
|
||||
})
|
||||
|
40
action.yml
40
action.yml
@ -6,21 +6,41 @@ branding:
|
||||
color: orange
|
||||
inputs:
|
||||
repo_token:
|
||||
description: 'GitHub token'
|
||||
description: 'GitHub token.'
|
||||
required: true
|
||||
default: ${{ github.token }}
|
||||
file:
|
||||
description: 'Local file to upload'
|
||||
required: true
|
||||
asset_name:
|
||||
description: 'Name of the asset'
|
||||
description: 'Local file to upload.'
|
||||
required: true
|
||||
tag:
|
||||
description: 'Tag to use as a release'
|
||||
description: 'Tag to use as a release.'
|
||||
required: true
|
||||
default: ${{ github.ref }}
|
||||
asset_name:
|
||||
description: 'Name of the asset. When not provided will use the file name. Unused if file_glob is set to "true".'
|
||||
overwrite:
|
||||
description: 'Overwrite the release in case it already exists'
|
||||
description: 'Overwrite the release in case it already exists.'
|
||||
promote:
|
||||
description: 'Promote a prerelease to release. Defaults to "false".'
|
||||
file_glob:
|
||||
description: 'if true the file can be a glob pattern, asset_name is ignored if this is true'
|
||||
description: 'If true the file can be a glob pattern, asset_name is ignored if this is true.'
|
||||
draft:
|
||||
description: 'Mark the release as a draft. Defaults to "false".'
|
||||
prerelease:
|
||||
description: 'Mark the release as a pre-release. Defaults to "false".'
|
||||
make_latest:
|
||||
description: 'Mark the release the latest release for the repository. Defaults to "true".'
|
||||
release_name:
|
||||
description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.'
|
||||
body:
|
||||
description: 'Content of the release text. Empty by default.'
|
||||
target_commit:
|
||||
description: 'Specifies the commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. Unused if the Git tag already exists. Default: the repository\"s default branch (usually `main`).'
|
||||
repo_name:
|
||||
description: 'Specify the name of the GitHub repository in which the GitHub release will be created, edited, and deleted. If the repository is other than the current, it is required to create a personal access token with `repo`, `user`, `admin:repo_hook` scopes to the foreign repository and add it as a secret. Defaults to the current repository'
|
||||
outputs:
|
||||
browser_download_url:
|
||||
description: 'The publicly available URL of the asset.'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'lib/main.js'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
39230
dist/index.js
vendored
Normal file
39230
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,22 +0,0 @@
|
||||
# Contributors
|
||||
|
||||
### Checkin
|
||||
|
||||
- Do checkin source (src)
|
||||
- Do checkin build output (lib)
|
||||
- Do checkin runtime node_modules
|
||||
- Do not checkin devDependency node_modules (husky can help see below)
|
||||
|
||||
### devDependencies
|
||||
|
||||
In order to handle correctly checking in node_modules without devDependencies, we run [Husky](https://github.com/typicode/husky) before each commit.
|
||||
This step ensures that formatting and checkin rules are followed and that devDependencies are excluded. To make sure Husky runs correctly, please use the following workflow:
|
||||
|
||||
```
|
||||
npm install # installs all devDependencies including Husky
|
||||
git add abc.ext # Add the files you've changed. This should include files in src, lib, and node_modules (see above)
|
||||
git commit -m "Informative commit message" # Commit. This will run Husky
|
||||
```
|
||||
|
||||
During the commit step, Husky will take care of formatting all files with [Prettier](https://github.com/prettier/prettier) as well as pruning out devDependencies using `npm prune --production`.
|
||||
It will also make sure these changes are appropriately included in your commit (no further work is needed)
|
111
lib/main.js
111
lib/main.js
@ -1,111 +0,0 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const path = __importStar(require("path"));
|
||||
const glob = require("glob");
|
||||
function get_release_by_tag(tag, octokit, context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
core.debug(`Getting release by tag ${tag}.`);
|
||||
return yield octokit.repos.getReleaseByTag(Object.assign({}, context.repo, { tag: tag }));
|
||||
}
|
||||
catch (error) {
|
||||
// If this returns 404, we need to create the release first.
|
||||
if (error.status === 404) {
|
||||
core.debug(`Release for tag ${tag} doesn't exist yet so we'll create it now.`);
|
||||
return yield octokit.repos.createRelease(Object.assign({}, context.repo, { tag_name: tag }));
|
||||
}
|
||||
else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
function upload_to_release(release, file, asset_name, tag, overwrite, octokit, context) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const stat = fs.statSync(file);
|
||||
if (!stat.isFile()) {
|
||||
core.debug(`Skipping ${file}, since its not a file`);
|
||||
return;
|
||||
}
|
||||
const file_size = stat.size;
|
||||
const file_bytes = fs.readFileSync(file);
|
||||
// Check for duplicates.
|
||||
const assets = yield octokit.repos.listAssetsForRelease(Object.assign({}, context.repo, { release_id: release.data.id }));
|
||||
const duplicate_asset = assets.data.find(a => a.name === asset_name);
|
||||
if (duplicate_asset !== undefined) {
|
||||
if (overwrite === "true") {
|
||||
core.debug(`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`);
|
||||
yield octokit.repos.deleteReleaseAsset(Object.assign({}, context.repo, { asset_id: duplicate_asset.id }));
|
||||
}
|
||||
else {
|
||||
core.setFailed(`An asset called ${asset_name} already exists.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`);
|
||||
}
|
||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`);
|
||||
yield octokit.repos.uploadReleaseAsset({
|
||||
url: release.data.upload_url,
|
||||
name: asset_name,
|
||||
file: file_bytes,
|
||||
headers: {
|
||||
"content-type": "binary/octet-stream",
|
||||
"content-length": file_size
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const token = core.getInput('repo_token', { required: true });
|
||||
const file = core.getInput('file', { required: true });
|
||||
const file_glob = core.getInput('file_glob');
|
||||
const tag = core.getInput('tag', { required: true }).replace("refs/tags/", "");
|
||||
const overwrite = core.getInput('overwrite');
|
||||
const octokit = new github.GitHub(token);
|
||||
const context = github.context;
|
||||
const release = yield get_release_by_tag(tag, octokit, context);
|
||||
if (file_glob === "true") {
|
||||
const files = glob.sync(file);
|
||||
if (files.length > 0) {
|
||||
for (let file of files) {
|
||||
const asset_name = path.basename(file);
|
||||
yield upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.setFailed("No files matching the glob pattern found.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
const asset_name = core.getInput('asset_name', { required: true });
|
||||
yield upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
run();
|
11925
package-lock.json
generated
11925
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
38
package.json
38
package.json
@ -1,12 +1,17 @@
|
||||
{
|
||||
"name": "upload-release-action",
|
||||
"version": "1.0.1",
|
||||
"version": "2.9.0",
|
||||
"private": true,
|
||||
"description": "Upload files to a GitHub release",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "jest"
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"pack": "ncc build",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -22,16 +27,27 @@
|
||||
"author": "Sven-Hendrik Haase",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.0.0",
|
||||
"@actions/github": "^1.0.0",
|
||||
"glob": "^7.1.4"
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@lifeomic/attempt": "^3.0.3",
|
||||
"@octokit/core": "^5.1.0",
|
||||
"glob": "^10"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.0.13",
|
||||
"@types/node": "^12.0.4",
|
||||
"jest": "^24.8.0",
|
||||
"jest-circus": "^24.7.1",
|
||||
"ts-jest": "^24.0.2",
|
||||
"typescript": "^3.5.1"
|
||||
"@octokit/types": "^12.5.0",
|
||||
"@types/jest": "^29",
|
||||
"@types/node": "^20",
|
||||
"@typescript-eslint/eslint-plugin": "^7.0.2",
|
||||
"@typescript-eslint/parser": "^7",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8",
|
||||
"eslint-plugin-github": "^4.10",
|
||||
"eslint-plugin-jest": "^27",
|
||||
"jest": "^29",
|
||||
"jest-circus": "^29",
|
||||
"js-yaml": "^4",
|
||||
"prettier": "^3.2",
|
||||
"ts-jest": "^29",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
347
src/main.ts
347
src/main.ts
@ -1,104 +1,277 @@
|
||||
import * as fs from 'fs';
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import * as path from 'path';
|
||||
import * as fs from 'fs'
|
||||
import {Octokit} from '@octokit/core'
|
||||
import {Endpoints} from '@octokit/types'
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import * as path from 'path'
|
||||
import * as glob from 'glob'
|
||||
import {retry} from '@lifeomic/attempt'
|
||||
|
||||
const glob = require("glob")
|
||||
const getRef = 'GET /repos/{owner}/{repo}/git/ref/{ref}' as const
|
||||
const releaseByTag = 'GET /repos/{owner}/{repo}/releases/tags/{tag}' as const
|
||||
const createRelease = 'POST /repos/{owner}/{repo}/releases' as const
|
||||
const updateRelease =
|
||||
'PATCH /repos/{owner}/{repo}/releases/{release_id}' as const
|
||||
const repoAssets =
|
||||
'GET /repos/{owner}/{repo}/releases/{release_id}/assets' as const
|
||||
const uploadAssets =
|
||||
'POST {origin}/repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}' as const
|
||||
const deleteAssets =
|
||||
'DELETE /repos/{owner}/{repo}/releases/assets/{asset_id}' as const
|
||||
|
||||
async function get_release_by_tag(tag: string, octokit: any, context: any): Promise<any> {
|
||||
try {
|
||||
core.debug(`Getting release by tag ${tag}.`);
|
||||
return await octokit.repos.getReleaseByTag({
|
||||
...context.repo,
|
||||
tag: tag,
|
||||
});
|
||||
} catch (error) {
|
||||
// If this returns 404, we need to create the release first.
|
||||
if (error.status === 404) {
|
||||
core.debug(`Release for tag ${tag} doesn't exist yet so we'll create it now.`)
|
||||
return await octokit.repos.createRelease({
|
||||
...context.repo,
|
||||
tag_name: tag,
|
||||
})
|
||||
} else {
|
||||
throw error;
|
||||
type ReleaseByTagResp = Endpoints[typeof releaseByTag]['response']
|
||||
type CreateReleaseResp = Endpoints[typeof createRelease]['response']
|
||||
type RepoAssetsResp = Endpoints[typeof repoAssets]['response']['data']
|
||||
type UploadAssetResp = Endpoints[typeof uploadAssets]['response']
|
||||
type UpdateReleaseResp = Endpoints[typeof updateRelease]['response']
|
||||
type UpdateReleaseParams = Endpoints[typeof updateRelease]['parameters']
|
||||
|
||||
async function get_release_by_tag(
|
||||
tag: string,
|
||||
draft: boolean,
|
||||
prerelease: boolean,
|
||||
make_latest: boolean,
|
||||
release_name: string,
|
||||
body: string,
|
||||
octokit: Octokit,
|
||||
overwrite: boolean,
|
||||
promote: boolean,
|
||||
target_commit: string
|
||||
): Promise<ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp> {
|
||||
let release: ReleaseByTagResp
|
||||
try {
|
||||
core.debug(`Getting release by tag ${tag}.`)
|
||||
release = await octokit.request(releaseByTag, {
|
||||
...repo(),
|
||||
tag: tag
|
||||
})
|
||||
} catch (error: any) {
|
||||
// If this returns 404, we need to create the release first.
|
||||
if (error.status === 404) {
|
||||
core.debug(
|
||||
`Release for tag ${tag} doesn't exist yet so we'll create it now.`
|
||||
)
|
||||
if (target_commit) {
|
||||
try {
|
||||
await octokit.request(getRef, {
|
||||
...repo(),
|
||||
ref: `tags/${tag}`
|
||||
})
|
||||
core.warning(
|
||||
`Ignoring target_commit as the tag ${tag} already exists`
|
||||
)
|
||||
} catch (tagError: any) {
|
||||
if (tagError.status !== 404) {
|
||||
throw tagError
|
||||
}
|
||||
}
|
||||
}
|
||||
return await octokit.request(createRelease, {
|
||||
...repo(),
|
||||
tag_name: tag,
|
||||
draft: draft,
|
||||
prerelease: prerelease,
|
||||
make_latest: make_latest ? 'true' : 'false',
|
||||
name: release_name,
|
||||
body: body,
|
||||
target_commitish: target_commit
|
||||
})
|
||||
} else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
let updateObject: Partial<UpdateReleaseParams> | undefined
|
||||
if (promote && release.data.prerelease) {
|
||||
core.debug(`The ${tag} is a prerelease, promoting it to a release.`)
|
||||
updateObject = updateObject || {}
|
||||
updateObject.prerelease = false
|
||||
}
|
||||
if (overwrite) {
|
||||
if (release_name && release.data.name !== release_name) {
|
||||
core.debug(
|
||||
`The ${tag} release already exists with a different name ${release.data.name} so we'll overwrite it.`
|
||||
)
|
||||
updateObject = updateObject || {}
|
||||
updateObject.name = release_name
|
||||
}
|
||||
if (body && release.data.body !== body) {
|
||||
core.debug(
|
||||
`The ${tag} release already exists with a different body ${release.data.body} so we'll overwrite it.`
|
||||
)
|
||||
updateObject = updateObject || {}
|
||||
updateObject.body = body
|
||||
}
|
||||
}
|
||||
if (updateObject) {
|
||||
return octokit.request(updateRelease, {
|
||||
...repo(),
|
||||
...updateObject,
|
||||
release_id: release.data.id
|
||||
})
|
||||
}
|
||||
return release
|
||||
}
|
||||
|
||||
async function upload_to_release(release: any, file: string, asset_name: string, tag: string, overwrite: string, octokit: any, context: any) {
|
||||
const stat = fs.statSync(file);
|
||||
if (!stat.isFile()) {
|
||||
core.debug(`Skipping ${file}, since its not a file`);
|
||||
return;
|
||||
}
|
||||
const file_size = stat.size;
|
||||
const file_bytes = fs.readFileSync(file);
|
||||
async function upload_to_release(
|
||||
release: ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp,
|
||||
file: string,
|
||||
asset_name: string,
|
||||
tag: string,
|
||||
overwrite: boolean,
|
||||
octokit: ReturnType<(typeof github)['getOctokit']>
|
||||
): Promise<undefined | string> {
|
||||
const stat = fs.statSync(file)
|
||||
if (!stat.isFile()) {
|
||||
core.debug(`Skipping ${file}, since its not a file`)
|
||||
return
|
||||
}
|
||||
const file_size = stat.size
|
||||
if (file_size === 0) {
|
||||
core.debug(`Skipping ${file}, since its size is 0`)
|
||||
return
|
||||
}
|
||||
|
||||
// Check for duplicates.
|
||||
const assets = await octokit.repos.listAssetsForRelease({
|
||||
...context.repo,
|
||||
release_id: release.data.id,
|
||||
});
|
||||
const duplicate_asset = assets.data.find(a => a.name === asset_name);
|
||||
if (duplicate_asset !== undefined) {
|
||||
if (overwrite === "true") {
|
||||
core.debug(`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`)
|
||||
await octokit.repos.deleteReleaseAsset({
|
||||
...context.repo,
|
||||
asset_id: duplicate_asset.id
|
||||
})
|
||||
} else {
|
||||
core.setFailed(`An asset called ${asset_name} already exists.`)
|
||||
return;
|
||||
}
|
||||
// Check for duplicates.
|
||||
const assets: RepoAssetsResp = await octokit.paginate(repoAssets, {
|
||||
...repo(),
|
||||
release_id: release.data.id
|
||||
})
|
||||
const duplicate_asset = assets.find(a => a.name === asset_name)
|
||||
if (duplicate_asset !== undefined) {
|
||||
if (overwrite) {
|
||||
core.debug(
|
||||
`An asset called ${asset_name} already exists in release ${tag} so we'll overwrite it.`
|
||||
)
|
||||
await octokit.request(deleteAssets, {
|
||||
...repo(),
|
||||
asset_id: duplicate_asset.id
|
||||
})
|
||||
} else {
|
||||
core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`);
|
||||
core.setFailed(`An asset called ${asset_name} already exists.`)
|
||||
return duplicate_asset.browser_download_url
|
||||
}
|
||||
} else {
|
||||
core.debug(
|
||||
`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`
|
||||
)
|
||||
}
|
||||
|
||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`)
|
||||
await octokit.repos.uploadReleaseAsset({
|
||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`)
|
||||
const uploaded_asset: UploadAssetResp = await retry(
|
||||
async () => {
|
||||
return octokit.request(uploadAssets, {
|
||||
...repo(),
|
||||
release_id: release.data.id,
|
||||
url: release.data.upload_url,
|
||||
name: asset_name,
|
||||
file: file_bytes,
|
||||
data: fs.createReadStream(file) as any,
|
||||
headers: {
|
||||
"content-type": "binary/octet-stream",
|
||||
"content-length": file_size
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const token = core.getInput('repo_token', { required: true });
|
||||
const file = core.getInput('file', { required: true });
|
||||
const file_glob = core.getInput('file_glob');
|
||||
const tag = core.getInput('tag', { required: true }).replace("refs/tags/", "");
|
||||
const overwrite = core.getInput('overwrite');
|
||||
|
||||
const octokit = new github.GitHub(token);
|
||||
const context = github.context;
|
||||
const release = await get_release_by_tag(tag, octokit, context);
|
||||
|
||||
if (file_glob === "true") {
|
||||
const files = glob.sync(file);
|
||||
if (files.length > 0) {
|
||||
for (let file of files) {
|
||||
const asset_name = path.basename(file);
|
||||
await upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.setFailed("No files matching the glob pattern found.");
|
||||
}
|
||||
'content-type': 'binary/octet-stream',
|
||||
'content-length': file_size
|
||||
}
|
||||
else {
|
||||
const asset_name = core.getInput('asset_name', { required: true });
|
||||
await upload_to_release(release, file, asset_name, tag, overwrite, octokit, context);
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
})
|
||||
},
|
||||
{
|
||||
maxAttempts: 3
|
||||
}
|
||||
)
|
||||
return uploaded_asset.data.browser_download_url
|
||||
}
|
||||
|
||||
run();
|
||||
function repo(): {owner: string; repo: string} {
|
||||
const repo_name = core.getInput('repo_name')
|
||||
// If we're not targeting a foreign repository, we can just return immediately and don't have to do extra work.
|
||||
if (!repo_name) {
|
||||
return github.context.repo
|
||||
}
|
||||
const owner = repo_name.substring(0, repo_name.indexOf('/'))
|
||||
if (!owner) {
|
||||
throw new Error(`Could not extract 'owner' from 'repo_name': ${repo_name}.`)
|
||||
}
|
||||
const repo_ = repo_name.substring(repo_name.indexOf('/') + 1)
|
||||
if (!repo_) {
|
||||
throw new Error(`Could not extract 'repo' from 'repo_name': ${repo_name}.`)
|
||||
}
|
||||
return {
|
||||
owner,
|
||||
repo: repo_
|
||||
}
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
// Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs
|
||||
const token = core.getInput('repo_token', {required: true})
|
||||
const file = core.getInput('file', {required: true})
|
||||
const tag = core
|
||||
.getInput('tag', {required: true})
|
||||
.replace('refs/tags/', '')
|
||||
.replace('refs/heads/', '')
|
||||
|
||||
const file_glob = core.getInput('file_glob') == 'true' ? true : false
|
||||
const overwrite = core.getInput('overwrite') == 'true' ? true : false
|
||||
const promote = core.getInput('promote') == 'true' ? true : false
|
||||
const draft = core.getInput('draft') == 'true' ? true : false
|
||||
const prerelease = core.getInput('prerelease') == 'true' ? true : false
|
||||
const make_latest = core.getInput('make_latest') != 'false' ? true : false
|
||||
const release_name = core.getInput('release_name')
|
||||
const target_commit = core.getInput('target_commit')
|
||||
const body = core
|
||||
.getInput('body')
|
||||
.replace(/%0A/gi, '\n')
|
||||
.replace(/%0D/gi, '\r')
|
||||
.replace(/%25/g, '%')
|
||||
|
||||
const octokit = github.getOctokit(token)
|
||||
const release = await get_release_by_tag(
|
||||
tag,
|
||||
draft,
|
||||
prerelease,
|
||||
make_latest,
|
||||
release_name,
|
||||
body,
|
||||
octokit,
|
||||
overwrite,
|
||||
promote,
|
||||
target_commit
|
||||
)
|
||||
|
||||
if (file_glob) {
|
||||
const files = glob.sync(file)
|
||||
if (files.length > 0) {
|
||||
for (const file_ of files) {
|
||||
const asset_name = path.basename(file_)
|
||||
const asset_download_url = await upload_to_release(
|
||||
release,
|
||||
file_,
|
||||
asset_name,
|
||||
tag,
|
||||
overwrite,
|
||||
octokit
|
||||
)
|
||||
core.setOutput('browser_download_url', asset_download_url)
|
||||
}
|
||||
} else {
|
||||
core.setFailed('No files matching the glob pattern found.')
|
||||
}
|
||||
} else {
|
||||
const asset_name =
|
||||
core.getInput('asset_name') !== ''
|
||||
? core.getInput('asset_name').replace(/\$tag/g, tag)
|
||||
: path.basename(file)
|
||||
const asset_download_url = await upload_to_release(
|
||||
release,
|
||||
file,
|
||||
asset_name,
|
||||
tag,
|
||||
overwrite,
|
||||
octokit
|
||||
)
|
||||
core.setOutput('browser_download_url', asset_download_url)
|
||||
}
|
||||
} catch (error: any) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
run()
|
||||
|
@ -1,63 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
// "noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user