diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a79715e..2127b48 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,10 +19,10 @@ jobs: uses: actions/checkout@v2 - name: normal mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: normal-mode-comment message: 'normal mode - create comment' @@ -31,14 +31,53 @@ jobs: run: echo "this step just prints this" - name: normal mode - update comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: normal-mode-comment message: 'normal mode - update comment' + message-path: + runs-on: ubuntu-20.04 + name: Use message-path to load message from file + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Create MESSAGE.md + run: echo "body from message-path" > MESSAGE.md + - name: message path - create comment + uses: ./ + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.inputs.number }} + id: message-path-comment + message-path: ./MESSAGE.md + + - name: message path - missing input + uses: ./ + continue-on-error: true + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.inputs.number }} + id: message-path-comment + message-path: ./MISSING_INPUT.md + + - name: message path - both inputs provided, should fail + uses: ./ + continue-on-error: true + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + repository: ${{ github.repository }} + number: ${{ github.event.inputs.number }} + id: message-path-comment + message-path: ./MISSING_INPUT.md + message: BOTH + issue-append-mode: runs-on: ubuntu-20.04 name: Append mode progress for issue comments @@ -47,22 +86,22 @@ jobs: uses: actions/checkout@v2 - name: append mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: append-mode-comment - message: 'append mode - create comment' + message: "append mode - create comment" - name: Do some work run: echo "this step just prints this" - name: append mode - append comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: append-mode-comment append: true @@ -76,10 +115,10 @@ jobs: uses: actions/checkout@v2 - name: recreate mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: recreate-mode-comment message: 'recreate mode - create comment' @@ -88,10 +127,10 @@ jobs: run: echo "this step just prints this" - name: recreate mode - append comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: recreate-mode-comment recreate: true @@ -105,22 +144,22 @@ jobs: uses: actions/checkout@v2 - name: normal mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: normal-mode-comment - message: 'normal mode - create comment' + message: "normal mode - create comment" - name: Do some work run: echo "this step just prints this" - name: normal mode - update comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: normal-mode-comment message: 'normal mode - update comment' @@ -133,10 +172,10 @@ jobs: uses: actions/checkout@v2 - name: append mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: append-mode-comment message: 'append mode - create comment' @@ -145,10 +184,10 @@ jobs: run: echo "this step just prints this" - name: append mode - append comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: append-mode-comment append: true @@ -162,10 +201,10 @@ jobs: uses: actions/checkout@v2 - name: recreate mode - create comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: recreate-mode-comment message: 'recreate mode - create comment' @@ -174,10 +213,10 @@ jobs: run: echo "this step just prints this" - name: recreate mode - append comment - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} commit-sha: ${{ github.event.inputs.sha }} id: recreate-mode-comment recreate: true @@ -192,10 +231,10 @@ jobs: uses: actions/checkout@v2 - name: Should error out and not comment anything - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: fail-mode-comment recreate: true @@ -211,10 +250,10 @@ jobs: uses: actions/checkout@v2 - name: Error out - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} commit-sha: ${{ github.event.inputs.sha }} id: fail-mode-issue-commit-both @@ -229,10 +268,10 @@ jobs: uses: actions/checkout@v2 - name: Error out - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} id: fail-mode-issue-commit-none message: 'should error out as both number and sha fields are not given' @@ -245,10 +284,10 @@ jobs: uses: actions/checkout@v2 - name: Should comment and fail this job - uses: hasura/comment-progress@test + uses: ./ with: github-token: ${{ secrets.GITHUB_TOKEN }} - repository: 'hasura/comment-progress' + repository: ${{ github.repository }} number: ${{ github.event.inputs.number }} id: fail-comment fail: true diff --git a/action.yml b/action.yml index 9010712..c95184a 100644 --- a/action.yml +++ b/action.yml @@ -1,41 +1,44 @@ -name: 'Comment Progress' -description: 'Notify progress by commenting on GitHub issues, pull requests, and commits' +name: "Comment Progress" +description: "Notify progress by commenting on GitHub issues, pull requests, and commits" branding: icon: message-square color: white inputs: github-token: - description: 'Github token' + description: "Github token" required: true repository: - description: 'Github repository' + description: "Github repository" required: true number: - description: 'Github issue or pull request number' + description: "Github issue or pull request number" required: false commit-sha: - description: 'Commit SHA' + description: "Commit SHA" require: false id: - description: 'Unique identifier for the comment' + description: "Unique identifier for the comment" required: true message: - description: 'Message to be commented' - required: true + description: "Message to be commented" + required: false + message-path: + description: "Read message from path" + required: false fail: - description: 'If true, the step will be marked as failure' + description: "If true, the step will be marked as failure" append: - description: 'If true, message will be appended to existing comment' + description: "If true, message will be appended to existing comment" required: false default: false recreate: - description: 'If true, message will be commented after deleting existing comment' + description: "If true, message will be commented after deleting existing comment" required: false default: false delete: - description: 'If true, the comment will be deleted' + description: "If true, the comment will be deleted" required: false default: false runs: - using: 'node12' - main: 'dist/index.js' + using: "node12" + main: "dist/index.js" diff --git a/dist/index.js b/dist/index.js index 395834c..ad21297 100644 --- a/dist/index.js +++ b/dist/index.js @@ -13,6 +13,8 @@ __nccwpck_require__.r(__webpack_exports__); var core = __nccwpck_require__(186); // EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js var github = __nccwpck_require__(438); +// EXTERNAL MODULE: external "fs" +var external_fs_ = __nccwpck_require__(747); // CONCATENATED MODULE: ./identifier.js function getCommentPrefix(identifier) { return ``; @@ -239,26 +241,39 @@ async function deleteMode(commenter, identifier) { + (async () => { try { - const repository = core.getInput("repository"); - const [owner, repo] = repository.split("/"); + const repository = core.getInput('repository'); + const [owner, repo] = repository.split('/'); if (!owner || !repo) { throw new Error(`Invalid repository: ${repository}`); } - const number = core.getInput("number"); - const commitSHA = core.getInput("commit-sha"); - const identifier = core.getInput("id"); - const appendComment = core.getInput("append"); - const recreateComment = core.getInput("recreate"); - const deleteComment = core.getInput("delete"); - const fail = core.getInput("fail"); - const githubToken = core.getInput("github-token"); - const message = core.getInput("message"); + const number = core.getInput('number'); + const commitSHA = core.getInput('commit-sha'); + const identifier = core.getInput('id'); + const appendComment = core.getInput('append'); + const recreateComment = core.getInput('recreate'); + const deleteComment = core.getInput('delete'); + const fail = core.getInput('fail'); + const githubToken = core.getInput('github-token'); + let message = core.getInput('message'); + const messagePath = core.getInput('message-path'); const octokit = github.getOctokit(githubToken); + if (messagePath && message) { + core.setFailed("Only one of 'message' or 'message-path' can be set."); + return; + } else if (messagePath && !(0,external_fs_.existsSync)(messagePath)) { + core.setFailed(`Input message-path: '${messagePath}' does not exist.`); + return; + } else if (messagePath) { + console.log(`Read from message-path: ${messagePath} `); + message = (0,external_fs_.readFileSync)(messagePath, 'utf-8'); + } + let commenter; try { commenter = getCommenter(octokit, { @@ -274,27 +289,27 @@ async function deleteMode(commenter, identifier) { let mode = normalMode; - if (appendComment === "true" && recreateComment === "true") { - core.setFailed("Not allowed to set both `append` and `recreate` to true."); + if (appendComment === 'true' && recreateComment === 'true') { + core.setFailed('Not allowed to set both `append` and `recreate` to true.'); return; } - if (deleteComment === "true" && (appendComment === "true" || recreateComment === "true")) { - core.setFailed("Not allowed to set `delete` to true with `append` or `recreate`."); + if (deleteComment === 'true' && (appendComment === 'true' || recreateComment === 'true')) { + core.setFailed('Not allowed to set `delete` to true with `append` or `recreate`.'); return; } - if (recreateComment === "true") { + if (recreateComment === 'true') { mode = recreateMode; - } else if (appendComment === "true") { + } else if (appendComment === 'true') { mode = appendMode; - } else if (deleteComment === "true") { + } else if (deleteComment === 'true') { mode = deleteMode; } await mode(commenter, identifier, message); - if (fail === "true") { + if (fail === 'true') { core.setFailed(message); } } catch (error) { diff --git a/index.js b/index.js index ab08b82..c49aba8 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,8 @@ import * as core from '@actions/core'; import * as github from '@actions/github'; -import { normalMode, recreateMode, appendMode, deleteMode } from './modes'; +import { existsSync, readFileSync } from 'fs'; import { getCommenter } from './comment/commenter'; +import { appendMode, deleteMode, normalMode, recreateMode } from './modes'; (async () => { try { @@ -19,10 +20,22 @@ import { getCommenter } from './comment/commenter'; const deleteComment = core.getInput('delete'); const fail = core.getInput('fail'); const githubToken = core.getInput('github-token'); - const message = core.getInput('message'); + let message = core.getInput('message'); + const messagePath = core.getInput('message-path'); const octokit = github.getOctokit(githubToken); + if (messagePath && message) { + core.setFailed("Only one of 'message' or 'message-path' can be set."); + return; + } else if (messagePath && !existsSync(messagePath)) { + core.setFailed(`Input message-path: '${messagePath}' does not exist.`); + return; + } else if (messagePath) { + console.log(`Read from message-path: ${messagePath} `); + message = readFileSync(messagePath, 'utf-8'); + } + let commenter; try { commenter = getCommenter(octokit, { diff --git a/package.json b/package.json index 9c9013d..4fffda5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "build": "ncc build index.js --license licenses.txt", + "build": "NODE_OPTIONS=--openssl-legacy-provider ncc build index.js --license licenses.txt", "lint": "eslint **/*.js" }, "keywords": [