62 Commits

Author SHA1 Message Date
Sven-Hendrik Haase
04733e069f This is 2.9.0 2024-02-21 22:43:46 +01:00
Sven-Hendrik Haase
7b5b755e5b Add CHANGELOG entry for #112 2024-02-21 22:40:15 +01:00
Sven-Hendrik Haase
17449a21ea Add draft release support (fixes #19) 2024-02-21 22:38:32 +01:00
Sven-Hendrik Haase
ec2ff03a5a Amend CHANGELOG 2024-02-21 22:32:30 +01:00
Sven-Hendrik Haase
ff23fb2574 This is 2.8.0 2024-02-21 22:30:30 +01:00
Sven-Hendrik Haase
8e438350b0 Bump all deps 2024-02-21 22:28:50 +01:00
Sven-Hendrik Haase
fe68892921 Merge pull request #113 from svenstaro/dependabot/npm_and_yarn/babel/traverse-7.23.2
Bump @babel/traverse from 7.22.8 to 7.23.2
2023-11-22 17:40:23 +01:00
Sven-Hendrik Haase
a13e7b5d40 Merge pull request #116 from der-eismann/update-to-node20
Update to node20
2023-11-22 17:39:45 +01:00
Philipp Trulson
a4bae284e7 Update to node20 2023-11-21 18:29:25 +01:00
dependabot[bot]
c19ddf4c20 Bump @babel/traverse from 7.22.8 to 7.23.2
Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.22.8 to 7.23.2.
- [Release notes](https://github.com/babel/babel/releases)
- [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md)
- [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse)

---
updated-dependencies:
- dependency-name: "@babel/traverse"
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-19 11:51:41 +00:00
ShonP40
2d9c0f4337 Updated the readme 2023-09-04 13:19:28 +03:00
ShonP40
615015f76e Forgot to add draft support here 2023-09-04 12:49:56 +03:00
ShonP40
e3374ce5b6 Ability to create draft releases 2023-09-04 10:06:26 +03:00
Sven-Hendrik Haase
1beeb572c1 2.7.0 2023-07-28 18:36:58 +02:00
Sven-Hendrik Haase
5206d34958 Bump deps 2023-07-28 18:34:08 +02:00
Sven-Hendrik Haase
80d7a7e41c Merge pull request #46 from Spikatrix/master
Allow setting an explicit target_commitish
2023-07-28 18:28:50 +02:00
Sven-Hendrik Haase
5eb2ffd70b Merge pull request #110 from svenstaro/dependabot/npm_and_yarn/word-wrap-1.2.4
Bump word-wrap from 1.2.3 to 1.2.4
2023-07-19 02:40:07 +02:00
dependabot[bot]
07af2f374a Bump word-wrap from 1.2.3 to 1.2.4
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-18 22:43:20 +00:00
Spikatrix
5164410c7d Push dist
Why do I always forget to do this?
2023-06-10 05:48:38 +00:00
Spikatrix
f47fb36ff1 Use the ref api to check if a tag exists 2023-06-10 05:46:02 +00:00
Spikatrix
212d4babf8 Rethrow getTag error if not 404 2023-06-10 03:58:27 +00:00
Spikatrix
7670b98fa0 Push dist files 2023-06-04 16:31:53 +05:30
Spikatrix
ac438791c4 Warn when target_commit is ignored 2023-06-04 15:01:54 +05:30
Spikatrix
545e4c402b Change single quotes to double quotes 2023-06-03 11:59:49 +05:30
Spikatrix
7d304ee154 master -> main 2023-06-01 07:32:03 +00:00
Spikatrix
3cff01dd32 Allow setting an explicit target_commitish 2023-06-01 04:55:54 +00:00
Sven-Hendrik Haase
a724093295 Fix CHANGELOG name 2023-05-31 19:38:21 +02:00
Sven-Hendrik Haase
2b9d2847a9 2.6.1 2023-05-31 19:36:01 +02:00
Sven-Hendrik Haase
f9beb0ad08 Merge pull request #108 from regevbr/#107
fix #197 - do not overwrite, if empty
2023-05-31 19:31:09 +02:00
regevbr
1662cfa449 fix #197 - do not overwrite, if empty 2023-05-31 10:52:21 +03:00
Sven-Hendrik Haase
a5002416a0 Document running npm update after changing version 2023-05-24 02:09:52 +02:00
Sven-Hendrik Haase
58d5258088 2.6.0 2023-05-23 22:33:22 +02:00
Sven-Hendrik Haase
ffc1afa9c0 Update CHANGELOG 2023-05-23 22:31:32 +02:00
Sven-Hendrik Haase
24bced81d9 Merge pull request #74 from regevbr/body
feature - promote prerelease
2023-05-23 22:30:22 +02:00
regevbr
794b3152e1 fix #42 - overwrite body and name as well 2023-05-23 22:55:20 +03:00
regevbr
b00963776a fix #42 - overwrite body and name as well 2023-05-23 22:54:48 +03:00
regevbr
210500d479 fix #42 - overwrite body and name as well 2023-05-23 09:49:27 +03:00
Sven-Hendrik Haase
f0dfba8919 Update CHANGELOG for overwrite fixes 2023-05-23 03:52:28 +02:00
Sven-Hendrik Haase
42c63808d6 Merge pull request #106 from regevbr/body_update
fix #42 - overwrite body and name as well
2023-05-23 03:49:38 +02:00
regevbr
febd7d0808 fix #42 - overwrite body and name as well 2023-05-22 23:52:51 +03:00
Sven-Hendrik Haase
d8e2a64134 Merge pull request #105 from svenstaro/bump-deps
Bump deps
2023-05-22 22:29:47 +02:00
Sven-Hendrik Haase
a4af572b12 Bump deps 2023-05-22 22:14:47 +02:00
Sven-Hendrik Haase
7d4e20c14b Bump deps 2023-05-22 20:54:45 +02:00
Sven-Hendrik Haase
7e467024cd Merge pull request #104 from regevbr/ci_fix
fix - fix ci
2023-05-22 20:50:04 +02:00
regevbr
e225e77501 fix - fix ci 2023-05-22 21:29:20 +03:00
Sven-Hendrik Haase
6295ff030e Update CHANGELOG 2023-05-22 02:19:26 +02:00
Sven-Hendrik Haase
37a32b0167 Merge pull request #100 from brandonkelly/make-latest
Add `make_latest` param
2023-05-22 02:15:00 +02:00
Sven-Hendrik Haase
0c6fec2cea Merge pull request #102 from Loyalsoldier/fix-file-empty
Fix: skip uploading empty files
2023-05-22 02:13:13 +02:00
Sven-Hendrik Haase
37f4f3a9cd Merge pull request #103 from Loyalsoldier/fix-lock
Fix: package version in lock file
2023-05-22 02:06:56 +02:00
Loyalsoldier
dfae8c036c Fix: package version in lock file 2023-05-11 14:55:32 +08:00
Loyalsoldier
99e2100a1f Fix: skip uploading empty files 2023-05-11 14:47:45 +08:00
Sven-Hendrik Haase
664a7c20c1 Better README markup 2023-04-27 17:29:08 +02:00
brandonkelly
760a5584dc make_latest param 2023-04-12 17:36:04 -07:00
Sven-Hendrik Haase
580065490f Merge pull request #98 from edgarrmondragon/document-granular-permissions
Document usage with granular permissions
2023-04-11 08:47:18 +02:00
Edgar Ramírez Mondragón
eed453b613 Document usage with granular permissions 2023-04-11 00:05:14 -06:00
Sven-Hendrik Haase
7319e4733e 2.5.0 2023-02-21 15:45:38 +01:00
Sven-Hendrik Haase
4e86b8565b Prepare release 2023-02-21 15:11:15 +01:00
Sven-Hendrik Haase
3a6baf0f12 Add CHANGELOG entry for retry feature 2023-02-21 15:08:59 +01:00
Sven-Hendrik Haase
e8c797e08e Merge pull request #96 from sonphantrung/retry-v2
Add retry to upload release (UPDATED VERSION)
2023-02-21 15:07:45 +01:00
Son Phan Trung
cf83be2c7f Merge branch 'master' into retry-v2 2023-02-21 20:08:09 +07:00
Son Phan Trung
cfdd9b50bd Merge branch 'retry' of https://github.com/messense/upload-release-action 2023-02-21 20:06:34 +07:00
messense
1819382cf9 Add retry to upload release 2022-07-03 11:23:10 +08:00
10 changed files with 37538 additions and 14693 deletions

View File

@@ -24,6 +24,7 @@
"@typescript-eslint/func-call-spacing": ["error", "never"], "@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error", "@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error", "@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "error", "@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error", "@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error", "@typescript-eslint/no-inferrable-types": "error",

View File

@@ -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
View File

@@ -2,3 +2,4 @@ node_modules
run.sh run.sh
__tests__/runner/* __tests__/runner/*
lib/**/* lib/**/*
.idea

View File

@@ -1,5 +1,28 @@
# Changelog # 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 ## [2.4.1] - 2023-02-01
- Modernize octokit usage - Modernize octokit usage

View File

@@ -15,10 +15,14 @@ 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`).
- `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`). - `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).
- `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: `""`). - `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 +210,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
@@ -213,6 +226,7 @@ To release this Action:
- Bump version in `package.json` - Bump version in `package.json`
- Create `CHANGELOG.md` entry - Create `CHANGELOG.md` entry
- `npm update`
- `npm run all` - `npm run all`
- `git commit -am <version>` - `git commit -am <version>`
- `git tag -sm <version> <version>` - `git tag -sm <version> <version>`

View File

@@ -20,19 +20,27 @@ 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.'
draft:
description: 'Mark the release as a draft. Defaults to "false".'
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:
description: 'Content of the release text. Empty by default.' 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: 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' 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: outputs:
browser_download_url: browser_download_url:
description: 'The publicly available URL of the asset.' description: 'The publicly available URL of the asset.'
runs: runs:
using: 'node16' using: 'node20'
main: 'dist/index.js' main: 'dist/index.js'

42765
dist/index.js vendored

File diff suppressed because one or more lines are too long

9238
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "upload-release-action", "name": "upload-release-action",
"version": "2.4.1", "version": "2.9.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",
@@ -27,24 +27,27 @@
"author": "Sven-Hendrik Haase", "author": "Sven-Hendrik Haase",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.0", "@actions/core": "^1.10.1",
"@actions/github": "^5", "@actions/github": "^6.0.0",
"glob": "^7" "@lifeomic/attempt": "^3.0.3",
"@octokit/core": "^5.1.0",
"glob": "^10"
}, },
"devDependencies": { "devDependencies": {
"@types/glob": "^7", "@octokit/types": "^12.5.0",
"@types/jest": "^29", "@types/jest": "^29",
"@types/node": "^16", "@types/node": "^20",
"@typescript-eslint/parser": "^5", "@typescript-eslint/eslint-plugin": "^7.0.2",
"@vercel/ncc": "^0.36.0", "@typescript-eslint/parser": "^7",
"@vercel/ncc": "^0.38.1",
"eslint": "^8", "eslint": "^8",
"eslint-plugin-github": "^4.6", "eslint-plugin-github": "^4.10",
"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": "^3.2",
"ts-jest": "^29", "ts-jest": "^29",
"typescript": "^4" "typescript": "^5"
} }
} }

View File

@@ -5,9 +5,13 @@ 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 getRef = 'GET /repos/{owner}/{repo}/git/ref/{ref}' as const
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 +23,25 @@ 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,
draft: boolean,
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,
target_commit: string
): 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
}) })
@@ -39,21 +51,69 @@ async function get_release_by_tag(
core.debug( core.debug(
`Release for tag ${tag} doesn't exist yet so we'll create it now.` `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, { return await octokit.request(createRelease, {
...repo(), ...repo(),
tag_name: tag, tag_name: tag,
draft: draft,
prerelease: prerelease, prerelease: prerelease,
make_latest: make_latest ? 'true' : 'false',
name: release_name, name: release_name,
body: body body: body,
target_commitish: target_commit
}) })
} else { } else {
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_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( 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 +126,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 +157,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,8 +210,12 @@ 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 draft = core.getInput('draft') == '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 target_commit = core.getInput('target_commit')
const body = core const body = core
.getInput('body') .getInput('body')
.replace(/%0A/gi, '\n') .replace(/%0A/gi, '\n')
@@ -151,10 +225,15 @@ async function run(): Promise<void> {
const octokit = github.getOctokit(token) const octokit = github.getOctokit(token)
const release = await get_release_by_tag( const release = await get_release_by_tag(
tag, tag,
draft,
prerelease, prerelease,
make_latest,
release_name, release_name,
body, body,
octokit octokit,
overwrite,
promote,
target_commit
) )
if (file_glob) { if (file_glob) {