Compare commits
40 Commits
ci-test-ub
...
2.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2728235f7d | ||
|
|
c2e0608dc4 | ||
|
|
bd74772a1a | ||
|
|
16e7903b2d | ||
|
|
f2c549b117 | ||
|
|
7a7d004438 | ||
|
|
9c4a92ec0d | ||
|
|
039214a996 | ||
|
|
2b373356cb | ||
|
|
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 |
@@ -24,7 +24,6 @@
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
50
README.md
50
README.md
@@ -7,12 +7,12 @@ 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.
|
||||
- `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).
|
||||
|
||||
Optional Arguments
|
||||
|
||||
- `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`)
|
||||
@@ -161,6 +161,52 @@ jobs:
|
||||
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@v2
|
||||
|
||||
# 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 "::set-output name=RELEASE_BODY::$r" # <--- 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
|
||||
|
||||
```
|
||||
|
||||
|
||||
## Releasing
|
||||
|
||||
To release this Action:
|
||||
|
||||
@@ -8,12 +8,14 @@ inputs:
|
||||
repo_token:
|
||||
description: 'GitHub token.'
|
||||
required: true
|
||||
default: ${{ github.token }}
|
||||
file:
|
||||
description: 'Local file to upload.'
|
||||
required: true
|
||||
tag:
|
||||
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:
|
||||
@@ -32,5 +34,5 @@ outputs:
|
||||
browser_download_url:
|
||||
description: 'The publicly available URL of the asset.'
|
||||
runs:
|
||||
using: 'node12'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
||||
24298
dist/index.js
vendored
24298
dist/index.js
vendored
File diff suppressed because one or more lines are too long
16814
package-lock.json
generated
16814
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
34
package.json
34
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "upload-release-action",
|
||||
"version": "2.2.1",
|
||||
"version": "2.4.0",
|
||||
"private": true,
|
||||
"description": "Upload files to a GitHub release",
|
||||
"main": "lib/main.js",
|
||||
@@ -27,24 +27,24 @@
|
||||
"author": "Sven-Hendrik Haase",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@types/glob": "^7.1.2",
|
||||
"glob": "^7.1.6"
|
||||
"@types/glob": "^8",
|
||||
"glob": "^8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^24.9.1",
|
||||
"@types/node": "^12.12.64",
|
||||
"@typescript-eslint/parser": "^3.5.0",
|
||||
"@zeit/ncc": "^0.22.3",
|
||||
"eslint": "^7.10.0",
|
||||
"eslint-plugin-github": "^4.0.1",
|
||||
"eslint-plugin-jest": "^23.17.1",
|
||||
"jest": "^26.5.2",
|
||||
"jest-circus": "^26.5.2",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "^2.0.5",
|
||||
"ts-jest": "^26.4.1",
|
||||
"typescript": "^3.9.6"
|
||||
"@types/jest": "^29",
|
||||
"@types/node": "^16",
|
||||
"@typescript-eslint/parser": "^5",
|
||||
"@vercel/ncc": "^0.36.0",
|
||||
"eslint": "^8",
|
||||
"eslint-plugin-github": "^4.6",
|
||||
"eslint-plugin-jest": "^27",
|
||||
"jest": "^29",
|
||||
"jest-circus": "^29",
|
||||
"js-yaml": "^4",
|
||||
"prettier": "^2.8",
|
||||
"ts-jest": "^29",
|
||||
"typescript": "^4"
|
||||
}
|
||||
}
|
||||
|
||||
35
src/main.ts
35
src/main.ts
@@ -6,10 +6,14 @@ import * as github from '@actions/github'
|
||||
import * as path from 'path'
|
||||
import * as glob from 'glob'
|
||||
|
||||
type RepoAssetsResp = Endpoints['GET /repos/:owner/:repo/releases/:release_id/assets']['response']['data']
|
||||
type ReleaseByTagResp = Endpoints['GET /repos/:owner/:repo/releases/tags/:tag']['response']
|
||||
type CreateReleaseResp = Endpoints['POST /repos/:owner/:repo/releases']['response']
|
||||
type UploadAssetResp = Endpoints['POST /repos/:owner/:repo/releases/:release_id/assets{?name,label}']['response']
|
||||
type RepoAssetsResp =
|
||||
Endpoints['GET /repos/:owner/:repo/releases/:release_id/assets']['response']['data']
|
||||
type ReleaseByTagResp =
|
||||
Endpoints['GET /repos/:owner/:repo/releases/tags/:tag']['response']
|
||||
type CreateReleaseResp =
|
||||
Endpoints['POST /repos/:owner/:repo/releases']['response']
|
||||
type UploadAssetResp =
|
||||
Endpoints['POST /repos/:owner/:repo/releases/:release_id/assets{?name,label}']['response']
|
||||
|
||||
async function get_release_by_tag(
|
||||
tag: string,
|
||||
@@ -24,7 +28,7 @@ async function get_release_by_tag(
|
||||
...repo(),
|
||||
tag: tag
|
||||
})
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
// If this returns 404, we need to create the release first.
|
||||
if (error.status === 404) {
|
||||
core.debug(
|
||||
@@ -88,8 +92,8 @@ async function upload_to_release(
|
||||
}
|
||||
|
||||
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`)
|
||||
const uploaded_asset: UploadAssetResp = await octokit.repos.uploadReleaseAsset(
|
||||
{
|
||||
const uploaded_asset: UploadAssetResp =
|
||||
await octokit.repos.uploadReleaseAsset({
|
||||
url: release.data.upload_url,
|
||||
name: asset_name,
|
||||
data: file_bytes,
|
||||
@@ -97,8 +101,7 @@ async function upload_to_release(
|
||||
'content-type': 'binary/octet-stream',
|
||||
'content-length': file_size
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
return uploaded_asset.data.browser_download_url
|
||||
}
|
||||
|
||||
@@ -112,13 +115,13 @@ function repo(): {owner: string; repo: string} {
|
||||
if (!owner) {
|
||||
throw new Error(`Could not extract 'owner' from 'repo_name': ${repo_name}.`)
|
||||
}
|
||||
const repo = repo_name.substr(repo_name.indexOf('/') + 1)
|
||||
if (!repo) {
|
||||
const repo_ = repo_name.substr(repo_name.indexOf('/') + 1)
|
||||
if (!repo_) {
|
||||
throw new Error(`Could not extract 'repo' from 'repo_name': ${repo_name}.`)
|
||||
}
|
||||
return {
|
||||
owner,
|
||||
repo
|
||||
repo: repo_
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,11 +153,11 @@ async function run(): Promise<void> {
|
||||
if (file_glob) {
|
||||
const files = glob.sync(file)
|
||||
if (files.length > 0) {
|
||||
for (const file of files) {
|
||||
const asset_name = path.basename(file)
|
||||
for (const file_ of files) {
|
||||
const asset_name = path.basename(file_)
|
||||
const asset_download_url = await upload_to_release(
|
||||
release,
|
||||
file,
|
||||
file_,
|
||||
asset_name,
|
||||
tag,
|
||||
overwrite,
|
||||
@@ -180,7 +183,7 @@ async function run(): Promise<void> {
|
||||
)
|
||||
core.setOutput('browser_download_url', asset_download_url)
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user