mirror of
https://github.com/expo/expo-github-action.git
synced 2026-11-15 17:32:45 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4175ed947 | ||
|
|
fbd44501d8 | ||
|
|
6931e3c78b | ||
|
|
3f293ee480 | ||
|
|
2e1fe6ac53 | ||
|
|
94c7d8acbd | ||
|
|
839215f036 | ||
|
|
d0148023e1 | ||
|
|
204dfed23c |
No files matched your search
@@ -1,6 +1,8 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
@@ -12,7 +14,8 @@ concurrency:
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
release:
|
||||
dryrun:
|
||||
if: ${{ github.ref != 'refs/heads/main' || github.event.inputs.release != 'release' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🏗 Setup repo
|
||||
@@ -25,16 +28,62 @@ jobs:
|
||||
cache: yarn
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
run: yarn install --frozen-lockfile --check-files
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: 📋 Dry-running release
|
||||
if: ${{ github.ref != 'refs/heads/main' || github.event.inputs.release != 'release' }}
|
||||
run: yarn semantic-release --dry-run
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
publish:
|
||||
if: ${{ github.ref == 'refs/heads/main' && github.event.inputs.release == 'release' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🏗 Setup repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 🏗 Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: yarn
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: 📋 Release code
|
||||
if: ${{ github.ref == 'refs/heads/main' && github.event.inputs.release == 'release' }}
|
||||
run: yarn semantic-release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
|
||||
tags:
|
||||
needs: publish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 🏗 Setup repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: 🏗 Setup Node
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
cache: yarn
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: 📦 Install semver
|
||||
run: yarn add --dev semver
|
||||
|
||||
- name: 🕵️ Resolve major version
|
||||
uses: actions/github-script@v6
|
||||
id: version
|
||||
with:
|
||||
result-encoding: string
|
||||
script: |
|
||||
const semver = require('semver')
|
||||
const { version } = require('./package.json')
|
||||
return semver.major(version)
|
||||
|
||||
- name: 📋 Update tags
|
||||
run: git tag --force v${{ steps.version.outputs.result }} && git push --force --tags
|
||||
@@ -5,6 +5,8 @@ on:
|
||||
- cron: '0 15 * * *'
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
types: [opened, synchronize]
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
@@ -76,8 +78,16 @@ jobs:
|
||||
script: |
|
||||
const message = `${{ steps.preview.outputs.message }}`
|
||||
if (!message) throw new Error('Message output is empty')
|
||||
|
||||
- name: 🧪 Comment on PR (github-token)
|
||||
uses: ./preview-comment
|
||||
env:
|
||||
EXPO_TEST_GITHUB_PULL: 149
|
||||
with:
|
||||
project: ./temp
|
||||
channel: test
|
||||
|
||||
- name: 🧪 Comment on PR
|
||||
- name: 🧪 Comment on PR (GITHUB_TOKEN)
|
||||
uses: ./preview-comment
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -85,5 +95,6 @@ jobs:
|
||||
with:
|
||||
project: ./temp
|
||||
channel: test
|
||||
github-token: badtoken
|
||||
|
||||
|
||||
@@ -1,3 +1,30 @@
|
||||
### [7.0.3](https://github.com/expo/expo-github-action/compare/7.0.2...7.0.3) (2022-02-14)
|
||||
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* improve invalid package version error handling ([#159](https://github.com/expo/expo-github-action/issues/159)) ([94c7d8a](https://github.com/expo/expo-github-action/commit/94c7d8acbd68c7dac4ecde503427c98849039499))
|
||||
* output error stacktraces in debug mode ([#160](https://github.com/expo/expo-github-action/issues/160)) ([6931e3c](https://github.com/expo/expo-github-action/commit/6931e3c78b432c1b94d84e684da42ecba46044b4))
|
||||
|
||||
|
||||
### Other chores
|
||||
|
||||
* always dry run a new release on merge ([#162](https://github.com/expo/expo-github-action/issues/162)) ([3f293ee](https://github.com/expo/expo-github-action/commit/3f293ee480f9d567c1c902848d26a5ca6720266b))
|
||||
* bump node-fetch from 2.6.1 to 2.6.7 ([#157](https://github.com/expo/expo-github-action/issues/157)) ([839215f](https://github.com/expo/expo-github-action/commit/839215f036182d3534f9b91d4573b9f126f56560))
|
||||
* fully automate releases ([#164](https://github.com/expo/expo-github-action/issues/164)) ([fbd4450](https://github.com/expo/expo-github-action/commit/fbd44501d896448c3c4ac4e5495bb536614fa3fc))
|
||||
|
||||
|
||||
### Documentation changes
|
||||
|
||||
* simplify expo cli versioning to latest ([#161](https://github.com/expo/expo-github-action/issues/161)) ([2e1fe6a](https://github.com/expo/expo-github-action/commit/2e1fe6ac53c6fd536ea5691410d73df35384fd07))
|
||||
|
||||
### [7.0.2](https://github.com/expo/expo-github-action/compare/7.0.1...7.0.2) (2022-01-25)
|
||||
|
||||
|
||||
### Code changes
|
||||
|
||||
* **preview-comment:** auto-fill the github token ([#156](https://github.com/expo/expo-github-action/issues/156)) ([204dfed](https://github.com/expo/expo-github-action/commit/204dfed23cb6416041ee5c918c7a6e3a5dbf8955))
|
||||
|
||||
### [7.0.1](https://github.com/expo/expo-github-action/compare/7.0.0...7.0.1) (2022-01-17)
|
||||
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ jobs:
|
||||
- name: 🏗 Setup Expo
|
||||
uses: expo/expo-github-action@v7
|
||||
with:
|
||||
expo-version: 5.x
|
||||
expo-version: latest
|
||||
token: ${{ secrets.EXPO_TOKEN }}
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
@@ -120,7 +120,7 @@ jobs:
|
||||
- name: 🏗 Setup Expo and EAS
|
||||
uses: expo/expo-github-action@v7
|
||||
with:
|
||||
expo-version: 5.x
|
||||
expo-version: latest
|
||||
eas-version: latest
|
||||
token: ${{ secrets.EXPO_TOKEN }}
|
||||
|
||||
@@ -159,7 +159,7 @@ jobs:
|
||||
- name: 🏗 Setup Expo
|
||||
uses: expo/expo-github-action@v7
|
||||
with:
|
||||
expo-version: 5.x
|
||||
expo-version: latest
|
||||
token: ${{ secrets.EXPO_TOKEN }}
|
||||
|
||||
- name: 📦 Install dependencies
|
||||
@@ -170,8 +170,6 @@ jobs:
|
||||
|
||||
- name: 💬 Comment preview
|
||||
uses: expo/expo-github-action/preview-comment@v7
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
channel: pr-${{ github.event.number }}
|
||||
```
|
||||
|
||||
+2264
-27
File diff suppressed because it is too large.
Load diff
@@ -638,6 +638,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
|
||||
tr46
|
||||
MIT
|
||||
|
||||
tunnel
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
@@ -699,6 +702,47 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
webidl-conversions
|
||||
BSD-2-Clause
|
||||
# The BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2014, Domenic Denicola
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
whatwg-url
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015–2016 Sebastian Mayr
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
wrappy
|
||||
ISC
|
||||
The ISC License
|
||||
|
||||
+2236
-7
File diff suppressed because it is too large.
Load diff
@@ -952,6 +952,9 @@ Redistribution and use in source and binary forms, with or without modification,
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
tr46
|
||||
MIT
|
||||
|
||||
tslib
|
||||
0BSD
|
||||
Copyright (c) Microsoft Corporation.
|
||||
@@ -1041,6 +1044,47 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
|
||||
webidl-conversions
|
||||
BSD-2-Clause
|
||||
# The BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2014, Domenic Denicola
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
whatwg-url
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015–2016 Sebastian Mayr
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
xml2js
|
||||
MIT
|
||||
Copyright 2010, 2011, 2012, 2013. All rights reserved.
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "expo-github-action",
|
||||
"version": "7.0.1",
|
||||
"version": "7.0.3",
|
||||
"description": "Expo CLI in your GitHub Actions workflow",
|
||||
"main": "build/index.js",
|
||||
"repository": {
|
||||
|
||||
@@ -44,6 +44,7 @@ Here is a summary of all the input options you can use.
|
||||
| **comment** | `true` | If this action should comment on a PR |
|
||||
| **message** | _[see code][code-defaults]_ | The message template |
|
||||
| **message-id** | _[see code][code-defaults]_ | A unique id template to prevent duplicate comments ([read more](#preventing-duplicate-comments)) |
|
||||
| **github-token** | `GITHUB_TOKEN` | A GitHub token to use when commenting on PR ([read more](#github-tokens)) |
|
||||
|
||||
## Available outputs
|
||||
|
||||
@@ -107,8 +108,6 @@ jobs:
|
||||
|
||||
- name: 💬 Comment in preview
|
||||
uses: expo/expo-github-action/preview-comment@v7
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
channel: pr-${{ github.event.number }}
|
||||
```
|
||||
@@ -173,6 +172,12 @@ jobs:
|
||||
When automating these preview comments, you have to be careful not to spam a pull request on every successful run.
|
||||
Every comment contains a generated **message-id** to identify previously made comments and update instead of creating a new comment.
|
||||
|
||||
### GitHub tokens
|
||||
|
||||
When using the GitHub API, you always need to be authenticated.
|
||||
This action tries to auto-authenticate using the [Automatic token authentication][link-gha-token] from GitHub.
|
||||
You can overwrite the token by adding the `GITHUB_TOKEN` environment variable, or add the **github-token** input.
|
||||
|
||||
<div align="center">
|
||||
<br />
|
||||
with :heart: <strong>byCedric</strong>
|
||||
@@ -181,3 +186,4 @@ Every comment contains a generated **message-id** to identify previously made co
|
||||
|
||||
[code-defaults]: ../src/actions/preview-comment.ts
|
||||
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
|
||||
[link-gha-token]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
|
||||
@@ -25,6 +25,10 @@ inputs:
|
||||
message-id:
|
||||
description: A unique identifier to prevent multiple comments on the same pull request
|
||||
required: false
|
||||
github-token:
|
||||
description: GitHub access token to comment on PRs
|
||||
required: false
|
||||
default: ${{ github.token }}
|
||||
outputs:
|
||||
projectOwner:
|
||||
description: The resolved project owner
|
||||
|
||||
@@ -20,6 +20,7 @@ export function commentInput() {
|
||||
message: getInput('message') || DEFAULT_MESSAGE,
|
||||
messageId: getInput('message-id') || DEFAULT_ID,
|
||||
project: getInput('project'),
|
||||
githubToken: getInput('github-token'),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -46,7 +47,9 @@ export async function commentAction(input: CommentInput = commentInput()) {
|
||||
if (!input.comment) {
|
||||
info(`Skipped comment: 'comment' is disabled`);
|
||||
} else {
|
||||
await createIssueComment(pullContext(), {
|
||||
await createIssueComment({
|
||||
...pullContext(),
|
||||
token: input.githubToken,
|
||||
id: messageId,
|
||||
body: messageBody,
|
||||
});
|
||||
|
||||
+25
-19
@@ -3,6 +3,11 @@ import { ok as assert } from 'assert';
|
||||
|
||||
type IssueContext = typeof context['issue'];
|
||||
|
||||
type AuthContext = {
|
||||
/** GitHub token from the 'github-input' to authenticate with */
|
||||
token?: string;
|
||||
};
|
||||
|
||||
type Comment = {
|
||||
/** A hidden identifier to embed in the comment */
|
||||
id: string;
|
||||
@@ -14,17 +19,17 @@ type Comment = {
|
||||
* Determine if a comment exists on an issue or pull with the provided identifier.
|
||||
* This will iterate all comments received from GitHub, and try to exit early if it exists.
|
||||
*/
|
||||
export async function fetchIssueComment(issue: IssueContext, commentId: Comment['id']) {
|
||||
const github = githubApi();
|
||||
export async function fetchIssueComment(options: AuthContext & IssueContext & Pick<Comment, 'id'>) {
|
||||
const github = githubApi(options);
|
||||
const iterator = github.paginate.iterator(github.rest.issues.listComments, {
|
||||
owner: issue.owner,
|
||||
repo: issue.repo,
|
||||
issue_number: issue.number,
|
||||
owner: options.owner,
|
||||
repo: options.repo,
|
||||
issue_number: options.number,
|
||||
});
|
||||
|
||||
for await (const { data: batch } of iterator) {
|
||||
for (const item of batch) {
|
||||
if ((item.body || '').includes(commentId)) {
|
||||
if ((item.body || '').includes(options.id)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -36,35 +41,36 @@ export async function fetchIssueComment(issue: IssueContext, commentId: Comment[
|
||||
* This includes a hidden identifier (markdown comment) to identify the comment later.
|
||||
* It will also update the comment when a previous comment id was found.
|
||||
*/
|
||||
export async function createIssueComment(issue: IssueContext, comment: Comment) {
|
||||
const github = githubApi();
|
||||
const body = `<!-- ${comment.id} -->\n${comment.body}`;
|
||||
const existing = await fetchIssueComment(issue, comment.id);
|
||||
export async function createIssueComment(options: AuthContext & IssueContext & Comment) {
|
||||
const github = githubApi(options);
|
||||
const body = `<!-- ${options.id} -->\n${options.body}`;
|
||||
const existing = await fetchIssueComment(options);
|
||||
|
||||
if (existing) {
|
||||
return github.rest.issues.updateComment({
|
||||
owner: issue.owner,
|
||||
repo: issue.repo,
|
||||
owner: options.owner,
|
||||
repo: options.repo,
|
||||
comment_id: existing.id,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
return github.rest.issues.createComment({
|
||||
owner: issue.owner,
|
||||
repo: issue.repo,
|
||||
issue_number: issue.number,
|
||||
owner: options.owner,
|
||||
repo: options.repo,
|
||||
issue_number: options.number,
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an authenticated octokit instance.
|
||||
* This uses the 'GITHUB_TOKEN' environment variable.
|
||||
* This uses the 'GITHUB_TOKEN' environment variable, or 'github-token' input.
|
||||
*/
|
||||
export function githubApi(): ReturnType<typeof getOctokit> {
|
||||
assert(process.env['GITHUB_TOKEN'], 'This step requires a GITHUB_TOKEN environment variable to create comments');
|
||||
return getOctokit(process.env['GITHUB_TOKEN']);
|
||||
export function githubApi(options: AuthContext = {}): ReturnType<typeof getOctokit> {
|
||||
const token = process.env['GITHUB_TOKEN'] || options.token;
|
||||
assert(token, `This step requires 'github-token' or a GITHUB_TOKEN environment variable to create comments`);
|
||||
return getOctokit(token);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,6 +17,11 @@ export async function resolvePackage(name: string, range: string): Promise<strin
|
||||
throw new Error(`Could not resolve ${name}@${range}, reason:\n${error.message || error}`);
|
||||
}
|
||||
|
||||
// thanks npm, for returning a "" json string value for invalid versions
|
||||
if (!stdout) {
|
||||
throw new Error(`Could not resolve ${name}@${range}, reason:\nInvalid version`);
|
||||
}
|
||||
|
||||
// thanks npm, for returning a "x.x.x" json value...
|
||||
if (stdout.startsWith('"')) {
|
||||
stdout = `[${stdout}]`;
|
||||
|
||||
+10
-3
@@ -1,4 +1,4 @@
|
||||
import { addPath, info, setFailed, warning } from '@actions/core';
|
||||
import { addPath, debug, info, setFailed, warning } from '@actions/core';
|
||||
import { exec } from '@actions/exec';
|
||||
import { ok as assert } from 'assert';
|
||||
import os from 'os';
|
||||
@@ -8,9 +8,16 @@ export { find as findTool, cacheDir as cacheTool } from '@actions/tool-cache';
|
||||
|
||||
/**
|
||||
* Auto-execute the action and pass errors to 'core.setFailed'.
|
||||
* It also passes the full error, with stacktrace, to 'core.debug'.
|
||||
* You'll need to enable debugging to view these full errors.
|
||||
*
|
||||
* @see https://github.com/actions/toolkit/blob/main/docs/action-debugging.md#step-debug-logs
|
||||
*/
|
||||
export async function executeAction(action: () => Promise<void>) {
|
||||
return action().catch(error => setFailed(error.message || error));
|
||||
export function executeAction(action: () => Promise<void>) {
|
||||
return action().catch((error: Error) => {
|
||||
setFailed(error.message || error);
|
||||
debug(error.stack || 'No stacktrace available');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ describe(commentInput, () => {
|
||||
message: DEFAULT_MESSAGE,
|
||||
messageId: DEFAULT_ID,
|
||||
project: undefined,
|
||||
githubToken: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -46,6 +47,11 @@ describe(commentInput, () => {
|
||||
mockInput({ channel: 'pr-420' });
|
||||
expect(commentInput()).toMatchObject({ channel: 'pr-420' });
|
||||
});
|
||||
|
||||
it('returns github-token', () => {
|
||||
mockInput({ 'github-token': 'fakegithubtoken' });
|
||||
expect(commentInput()).toMatchObject({ githubToken: 'fakegithubtoken' });
|
||||
});
|
||||
});
|
||||
|
||||
describe(commentAction, () => {
|
||||
@@ -55,6 +61,7 @@ describe(commentAction, () => {
|
||||
message: DEFAULT_MESSAGE,
|
||||
messageId: DEFAULT_ID,
|
||||
project: '',
|
||||
githubToken: '',
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
+19
-3
@@ -8,18 +8,34 @@ jest.mock('@actions/github');
|
||||
describe(githubApi, () => {
|
||||
afterEach(resetEnv);
|
||||
|
||||
it('throws when GITHUB_TOKEN is undefined', () => {
|
||||
it('throws when GITHUB_TOKEN and input are undefined', () => {
|
||||
setEnv('GITHUB_TOKEN', '');
|
||||
expect(() => githubApi()).toThrow(`requires a GITHUB_TOKEN`);
|
||||
expect(() => githubApi()).toThrow(`requires 'github-token' or a GITHUB_TOKEN`);
|
||||
});
|
||||
|
||||
it('returns an octokit instance', () => {
|
||||
it('returns octokit instance with GITHUB_TOKEN', () => {
|
||||
setEnv('GITHUB_TOKEN', 'fakegithubtoken');
|
||||
const fakeGithub = {};
|
||||
jest.mocked(github.getOctokit).mockReturnValue(fakeGithub as any);
|
||||
expect(githubApi()).toBe(fakeGithub);
|
||||
expect(github.getOctokit).toBeCalledWith('fakegithubtoken');
|
||||
});
|
||||
|
||||
it('returns octokit instance with input', () => {
|
||||
setEnv('GITHUB_TOKEN', '');
|
||||
const fakeGithub = {};
|
||||
jest.mocked(github.getOctokit).mockReturnValue(fakeGithub as any);
|
||||
expect(githubApi({ token: 'fakegithubtoken' })).toBe(fakeGithub);
|
||||
expect(github.getOctokit).toBeCalledWith('fakegithubtoken');
|
||||
});
|
||||
|
||||
it('uses GITHUB_TOKEN before input', () => {
|
||||
setEnv('GITHUB_TOKEN', 'fakegithubtoken');
|
||||
const fakeGithub = {};
|
||||
jest.mocked(github.getOctokit).mockReturnValue(fakeGithub as any);
|
||||
expect(githubApi({ token: 'badfakegithubtoken' })).toBe(fakeGithub);
|
||||
expect(github.getOctokit).toBeCalledWith('fakegithubtoken');
|
||||
});
|
||||
});
|
||||
|
||||
describe(pullContext, () => {
|
||||
|
||||
@@ -22,4 +22,8 @@ describe(resolvePackage, () => {
|
||||
'Could not resolve'
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects expo-cli@9999999 with proper error', async () => {
|
||||
await expect(resolvePackage('expo-cli', '9999999')).rejects.toThrow('Could not resolve');
|
||||
});
|
||||
});
|
||||
@@ -92,4 +92,19 @@ describe(executeAction, () => {
|
||||
await expect(executeAction(action)).resolves.not.toThrow();
|
||||
expect(core.setFailed).toBeCalledWith(error.message);
|
||||
});
|
||||
|
||||
it('provides full stacktrace to debug', async () => {
|
||||
const error = new Error('fake error');
|
||||
const action = jest.fn(() => Promise.reject(error));
|
||||
await expect(executeAction(action)).resolves.not.toThrow();
|
||||
expect(core.debug).toBeCalledWith(error.stack);
|
||||
});
|
||||
|
||||
it('provides fallback stacktrace to debug', async () => {
|
||||
const error = new Error('fake error');
|
||||
error.stack = undefined;
|
||||
const action = jest.fn(() => Promise.reject(error));
|
||||
await expect(executeAction(action)).resolves.not.toThrow();
|
||||
expect(core.debug).toBeCalledWith('No stacktrace available');
|
||||
});
|
||||
});
|
||||
@@ -5084,9 +5084,11 @@ node-emoji@^1.10.0:
|
||||
lodash.toarray "^4.4.0"
|
||||
|
||||
node-fetch@^2.6.0, node-fetch@^2.6.1:
|
||||
version "2.6.1"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
|
||||
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
|
||||
version "2.6.7"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
|
||||
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
|
||||
dependencies:
|
||||
whatwg-url "^5.0.0"
|
||||
|
||||
node-gyp@^7.1.0, node-gyp@^7.1.2:
|
||||
version "7.1.2"
|
||||
@@ -6642,6 +6644,11 @@ tr46@^2.1.0:
|
||||
dependencies:
|
||||
punycode "^2.1.1"
|
||||
|
||||
tr46@~0.0.3:
|
||||
version "0.0.3"
|
||||
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
|
||||
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=
|
||||
|
||||
traverse@~0.6.6:
|
||||
version "0.6.6"
|
||||
resolved "https://registry.yarnpkg.com/traverse/-/traverse-0.6.6.tgz#cbdf560fd7b9af632502fed40f918c157ea97137"
|
||||
@@ -6925,6 +6932,11 @@ wcwidth@^1.0.0:
|
||||
dependencies:
|
||||
defaults "^1.0.3"
|
||||
|
||||
webidl-conversions@^3.0.0:
|
||||
version "3.0.1"
|
||||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
|
||||
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=
|
||||
|
||||
webidl-conversions@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
|
||||
@@ -6947,6 +6959,14 @@ whatwg-mimetype@^2.3.0:
|
||||
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
|
||||
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==
|
||||
|
||||
whatwg-url@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
|
||||
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
|
||||
dependencies:
|
||||
tr46 "~0.0.3"
|
||||
webidl-conversions "^3.0.0"
|
||||
|
||||
whatwg-url@^8.0.0, whatwg-url@^8.5.0:
|
||||
version "8.6.0"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.6.0.tgz#27c0205a4902084b872aecb97cf0f2a7a3011f4c"
|
||||
|
||||
Reference in new issue
Block a user