Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into ypresto-log-url
  • Loading branch information
chrnorm committed May 21, 2022
2 parents d2d29a3 + e8c231a commit a481480
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 35 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Works great with my other action to create Deployments, [chrnorm/deployment-acti
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `state` | The state to set the deployment to. Must be one of the below: "error" "failure" "inactive" "in_progress" "queued" "pending" "success" |
| `token` | GitHub token |
| `target_url` | (Optional) The target URL. This should be the URL of the app once deployed |
| `log_url` | (Optional) Sets the URL for deployment output |
| `description` | (Optional) Descriptive message about the deployment |
| `environment_url` | (Optional) Sets the URL for accessing your environment |
| `deployment_id` | The ID of the deployment to update |
Expand Down Expand Up @@ -38,7 +38,7 @@ jobs:
id: deployment
with:
token: "${{ github.token }}"
target_url: http://my-app-url.com
environment_url: http://my-app-url.com
environment: production

- name: Deploy my app
Expand All @@ -50,7 +50,7 @@ jobs:
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
target_url: http://my-app-url.com
environment_url: http://my-app-url.com
state: "success"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}

Expand All @@ -59,7 +59,7 @@ jobs:
uses: chrnorm/deployment-status@releases/v1
with:
token: "${{ github.token }}"
target_url: http://my-app-url.com
environment_url: http://my-app-url.com
state: "failure"
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
```
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ inputs:
token:
description: "Github repository token"
required: true
log_url:
description: "Sets the URL for deployment output"
required: false
target_url:
description: "Target url location"
description: "Same as log_url"
required: false
environment_url:
description: "Sets the URL for accessing your environment"
Expand Down
92 changes: 65 additions & 27 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,78 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
var __awaiter =
(this && this.__awaiter) ||
function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done
? resolve(result.value)
: new P(function (resolve) {
resolve(result.value);
}).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
};
var __importStar =
(this && this.__importStar) ||
function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const context = github.context;
const defaultUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`;
const token = core.getInput("token", { required: true });
const url = core.getInput("target_url", { required: false }) || defaultUrl;
const description = core.getInput("description", { required: false }) || "";
const deploymentId = core.getInput("deployment_id");
const environmentUrl = core.getInput("environment_url", { required: false }) || "";
const state = core.getInput("state");
const client = new github.GitHub(token, { previews: ["flash", "ant-man"] });
yield client.repos.createDeploymentStatus(Object.assign({}, context.repo, { deployment_id: parseInt(deploymentId), state, target_url: url, description, environment_url: environmentUrl }));
}
catch (error) {
core.error(error);
core.setFailed(error.message);
}
});
return __awaiter(this, void 0, void 0, function* () {
try {
const context = github.context;
const defaultLogUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`;
const token = core.getInput("token", { required: true });
const logUrl =
core.getInput("log_url", { required: false }) ||
core.getInput("target_url", { required: false }) ||
defaultLogUrl;
const description =
core.getInput("description", { required: false }) || "";
const deploymentId = core.getInput("deployment_id");
const environmentUrl =
core.getInput("environment_url", { required: false }) || "";
const state = core.getInput("state");
const client = new github.GitHub(token, {
previews: ["flash", "ant-man"],
});
yield client.repos.createDeploymentStatus(
Object.assign({}, context.repo, {
deployment_id: parseInt(deploymentId),
state,
target_url: url,
description,
environment_url: environmentUrl,
})
);
} catch (error) {
core.error(error);
core.setFailed(error.message);
}
});
}
run();
9 changes: 6 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ type DeploymentState =
async function run() {
try {
const context = github.context;
const defaultUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`;
const defaultLogUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${context.sha}/checks`;

const token = core.getInput("token", { required: true });
const url = core.getInput("target_url", { required: false }) || defaultUrl;
const logUrl =
core.getInput("log_url", { required: false }) ||
core.getInput("target_url", { required: false }) ||
defaultLogUrl;
const description = core.getInput("description", { required: false }) || "";
const deploymentId = core.getInput("deployment_id");
const environmentUrl =
Expand All @@ -29,7 +32,7 @@ async function run() {
...context.repo,
deployment_id: parseInt(deploymentId),
state,
target_url: url,
log_url: logUrl,
description,
environment_url: environmentUrl,
});
Expand Down

0 comments on commit a481480

Please sign in to comment.