Compare commits
31 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 | ||
|
|
1819382cf9 |
39
.github/workflows/ci.yml
vendored
39
.github/workflows/ci.yml
vendored
@@ -31,6 +31,7 @@ jobs:
|
|||||||
tag: ci-test-${{ matrix.os }}-${{ github.run_id }}
|
tag: ci-test-${{ matrix.os }}-${{ github.run_id }}
|
||||||
overwrite: true
|
overwrite: true
|
||||||
prerelease: true
|
prerelease: true
|
||||||
|
make_latest: true
|
||||||
body: "rofl lol test%0Aianal %25 fubar"
|
body: "rofl lol test%0Aianal %25 fubar"
|
||||||
- name: Check that the uploaded asset is readable
|
- name: Check that the uploaded asset is readable
|
||||||
uses: actions/github-script@v2
|
uses: actions/github-script@v2
|
||||||
@@ -38,10 +39,9 @@ jobs:
|
|||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const child_process = require('child_process');
|
|
||||||
const assert = require('assert').strict;
|
const assert = require('assert').strict;
|
||||||
|
|
||||||
const expected = fs.readFileSync("README.md")
|
const expected = fs.readFileSync("README.md", "utf-8")
|
||||||
const release = await github.repos.getReleaseByTag({
|
const release = await github.repos.getReleaseByTag({
|
||||||
...context.repo,
|
...context.repo,
|
||||||
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
tag: "ci-test-${{ matrix.os }}-${{ github.run_id }}",
|
||||||
@@ -49,8 +49,39 @@ jobs:
|
|||||||
assert.deepStrictEqual(release.data.prerelease, true)
|
assert.deepStrictEqual(release.data.prerelease, true)
|
||||||
assert.deepStrictEqual(release.data.body, "rofl lol test\nianal % fubar")
|
assert.deepStrictEqual(release.data.body, "rofl lol test\nianal % fubar")
|
||||||
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
|
assert.deepStrictEqual(release.data.assets[0].name, "TEST.md")
|
||||||
const actual = child_process.execSync(`curl -Ls ${release.data.assets[0].browser_download_url}`)
|
const actual = await github.request(release.data.assets[0].browser_download_url)
|
||||||
assert.deepStrictEqual(expected, actual)
|
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
|
- name: Clean up
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
uses: actions/github-script@v2
|
uses: actions/github-script@v2
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ node_modules
|
|||||||
run.sh
|
run.sh
|
||||||
__tests__/runner/*
|
__tests__/runner/*
|
||||||
lib/**/*
|
lib/**/*
|
||||||
|
.idea
|
||||||
|
|||||||
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [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
|
## [2.4.1] - 2023-02-01
|
||||||
- Modernize octokit usage
|
- Modernize octokit usage
|
||||||
|
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -15,9 +15,11 @@ Optional Arguments
|
|||||||
- `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`.
|
- `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.
|
- `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`.
|
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`)
|
- `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`).
|
- `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`).
|
||||||
- `prerelease`: Mark the release as a pre-release (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).
|
- `release_name`: Explicitly set a release name. (Defaults: implicitly same as `tag` via GitHub API).
|
||||||
- `body`: Content of the release text (Default: `""`).
|
- `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).
|
- `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).
|
||||||
@@ -206,6 +208,15 @@ jobs:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 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
|
## Releasing
|
||||||
|
|
||||||
|
|||||||
@@ -20,10 +20,14 @@ inputs:
|
|||||||
description: 'Name of the asset. When not provided will use the file name. Unused if file_glob is set to "true".'
|
description: 'Name of the asset. When not provided will use the file name. Unused if file_glob is set to "true".'
|
||||||
overwrite:
|
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:
|
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.'
|
||||||
prerelease:
|
prerelease:
|
||||||
description: 'Mark the release as a pre-release. Defaults to "false".'
|
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:
|
release_name:
|
||||||
description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.'
|
description: 'Explicitly set a release name. Defaults to empty which will cause the release to take the tag as name on GitHub.'
|
||||||
body:
|
body:
|
||||||
|
|||||||
12660
dist/index.js
vendored
12660
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
4177
package-lock.json
generated
4177
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "upload-release-action",
|
"name": "upload-release-action",
|
||||||
"version": "2.4.1",
|
"version": "2.6.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Upload files to a GitHub release",
|
"description": "Upload files to a GitHub release",
|
||||||
"main": "lib/main.js",
|
"main": "lib/main.js",
|
||||||
@@ -28,23 +28,26 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/github": "^5",
|
"@actions/github": "^5.1.1",
|
||||||
"glob": "^7"
|
"@lifeomic/attempt": "^3.0.3",
|
||||||
|
"@octokit/core": "^4.2.1",
|
||||||
|
"glob": "^10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/glob": "^7",
|
"@octokit/types": "^9.2.3",
|
||||||
|
"@types/glob": "^8",
|
||||||
"@types/jest": "^29",
|
"@types/jest": "^29",
|
||||||
"@types/node": "^16",
|
"@types/node": "^16",
|
||||||
"@typescript-eslint/parser": "^5",
|
"@typescript-eslint/parser": "^5",
|
||||||
"@vercel/ncc": "^0.36.0",
|
"@vercel/ncc": "^0.36.1",
|
||||||
"eslint": "^8",
|
"eslint": "^8",
|
||||||
"eslint-plugin-github": "^4.6",
|
"eslint-plugin-github": "^4.7",
|
||||||
"eslint-plugin-jest": "^27",
|
"eslint-plugin-jest": "^27",
|
||||||
"jest": "^29",
|
"jest": "^29",
|
||||||
"jest-circus": "^29",
|
"jest-circus": "^29",
|
||||||
"js-yaml": "^4",
|
"js-yaml": "^4",
|
||||||
"prettier": "^2.8",
|
"prettier": "^2.8",
|
||||||
"ts-jest": "^29",
|
"ts-jest": "^29",
|
||||||
"typescript": "^4"
|
"typescript": "^5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
87
src/main.ts
87
src/main.ts
@@ -5,9 +5,12 @@ import * as core from '@actions/core'
|
|||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as glob from 'glob'
|
import * as glob from 'glob'
|
||||||
|
import {retry} from '@lifeomic/attempt'
|
||||||
|
|
||||||
const releaseByTag = 'GET /repos/{owner}/{repo}/releases/tags/{tag}' as const
|
const releaseByTag = 'GET /repos/{owner}/{repo}/releases/tags/{tag}' as const
|
||||||
const createRelease = 'POST /repos/{owner}/{repo}/releases' as const
|
const createRelease = 'POST /repos/{owner}/{repo}/releases' as const
|
||||||
|
const updateRelease =
|
||||||
|
'PATCH /repos/{owner}/{repo}/releases/{release_id}' as const
|
||||||
const repoAssets =
|
const repoAssets =
|
||||||
'GET /repos/{owner}/{repo}/releases/{release_id}/assets' as const
|
'GET /repos/{owner}/{repo}/releases/{release_id}/assets' as const
|
||||||
const uploadAssets =
|
const uploadAssets =
|
||||||
@@ -19,17 +22,23 @@ type ReleaseByTagResp = Endpoints[typeof releaseByTag]['response']
|
|||||||
type CreateReleaseResp = Endpoints[typeof createRelease]['response']
|
type CreateReleaseResp = Endpoints[typeof createRelease]['response']
|
||||||
type RepoAssetsResp = Endpoints[typeof repoAssets]['response']['data']
|
type RepoAssetsResp = Endpoints[typeof repoAssets]['response']['data']
|
||||||
type UploadAssetResp = Endpoints[typeof uploadAssets]['response']
|
type UploadAssetResp = Endpoints[typeof uploadAssets]['response']
|
||||||
|
type UpdateReleaseResp = Endpoints[typeof updateRelease]['response']
|
||||||
|
type UpdateReleaseParams = Endpoints[typeof updateRelease]['parameters']
|
||||||
|
|
||||||
async function get_release_by_tag(
|
async function get_release_by_tag(
|
||||||
tag: string,
|
tag: string,
|
||||||
prerelease: boolean,
|
prerelease: boolean,
|
||||||
|
make_latest: boolean,
|
||||||
release_name: string,
|
release_name: string,
|
||||||
body: string,
|
body: string,
|
||||||
octokit: Octokit
|
octokit: Octokit,
|
||||||
): Promise<ReleaseByTagResp | CreateReleaseResp> {
|
overwrite: boolean,
|
||||||
|
promote: boolean
|
||||||
|
): Promise<ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp> {
|
||||||
|
let release: ReleaseByTagResp
|
||||||
try {
|
try {
|
||||||
core.debug(`Getting release by tag ${tag}.`)
|
core.debug(`Getting release by tag ${tag}.`)
|
||||||
return await octokit.request(releaseByTag, {
|
release = await octokit.request(releaseByTag, {
|
||||||
...repo(),
|
...repo(),
|
||||||
tag: tag
|
tag: tag
|
||||||
})
|
})
|
||||||
@@ -43,6 +52,7 @@ async function get_release_by_tag(
|
|||||||
...repo(),
|
...repo(),
|
||||||
tag_name: tag,
|
tag_name: tag,
|
||||||
prerelease: prerelease,
|
prerelease: prerelease,
|
||||||
|
make_latest: make_latest ? 'true' : 'false',
|
||||||
name: release_name,
|
name: release_name,
|
||||||
body: body
|
body: body
|
||||||
})
|
})
|
||||||
@@ -50,10 +60,40 @@ async function get_release_by_tag(
|
|||||||
throw error
|
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.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 (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(
|
async function upload_to_release(
|
||||||
release: ReleaseByTagResp | CreateReleaseResp,
|
release: ReleaseByTagResp | CreateReleaseResp | UpdateReleaseResp,
|
||||||
file: string,
|
file: string,
|
||||||
asset_name: string,
|
asset_name: string,
|
||||||
tag: string,
|
tag: string,
|
||||||
@@ -66,7 +106,10 @@ async function upload_to_release(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const file_size = stat.size
|
const file_size = stat.size
|
||||||
const file_bytes: any = fs.createReadStream(file)
|
if (file_size === 0) {
|
||||||
|
core.debug(`Skipping ${file}, since its size is 0`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Check for duplicates.
|
// Check for duplicates.
|
||||||
const assets: RepoAssetsResp = await octokit.paginate(repoAssets, {
|
const assets: RepoAssetsResp = await octokit.paginate(repoAssets, {
|
||||||
@@ -94,17 +137,24 @@ async function upload_to_release(
|
|||||||
}
|
}
|
||||||
|
|
||||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`)
|
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`)
|
||||||
const uploaded_asset: UploadAssetResp = await octokit.request(uploadAssets, {
|
const uploaded_asset: UploadAssetResp = await retry(
|
||||||
...repo(),
|
async () => {
|
||||||
release_id: release.data.id,
|
return octokit.request(uploadAssets, {
|
||||||
url: release.data.upload_url,
|
...repo(),
|
||||||
name: asset_name,
|
release_id: release.data.id,
|
||||||
data: file_bytes,
|
url: release.data.upload_url,
|
||||||
headers: {
|
name: asset_name,
|
||||||
'content-type': 'binary/octet-stream',
|
data: fs.createReadStream(file) as any,
|
||||||
'content-length': file_size
|
headers: {
|
||||||
|
'content-type': 'binary/octet-stream',
|
||||||
|
'content-length': file_size
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
maxAttempts: 3
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
return uploaded_asset.data.browser_download_url
|
return uploaded_asset.data.browser_download_url
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +190,9 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
const file_glob = core.getInput('file_glob') == 'true' ? true : false
|
const file_glob = core.getInput('file_glob') == 'true' ? true : false
|
||||||
const overwrite = core.getInput('overwrite') == 'true' ? true : false
|
const overwrite = core.getInput('overwrite') == 'true' ? true : false
|
||||||
|
const promote = core.getInput('promote') == 'true' ? true : false
|
||||||
const prerelease = core.getInput('prerelease') == '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 release_name = core.getInput('release_name')
|
||||||
const body = core
|
const body = core
|
||||||
.getInput('body')
|
.getInput('body')
|
||||||
@@ -152,9 +204,12 @@ async function run(): Promise<void> {
|
|||||||
const release = await get_release_by_tag(
|
const release = await get_release_by_tag(
|
||||||
tag,
|
tag,
|
||||||
prerelease,
|
prerelease,
|
||||||
|
make_latest,
|
||||||
release_name,
|
release_name,
|
||||||
body,
|
body,
|
||||||
octokit
|
octokit,
|
||||||
|
overwrite,
|
||||||
|
promote
|
||||||
)
|
)
|
||||||
|
|
||||||
if (file_glob) {
|
if (file_glob) {
|
||||||
|
|||||||
Reference in New Issue
Block a user