Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty output object #38

Merged
merged 7 commits into from
Apr 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 32 additions & 102 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const axios = require("axios");
const { stripIndents } = require("common-tags");
const core = require("@actions/core");
const github = require("@actions/github");
Expand All @@ -8,39 +7,24 @@ const exec = require("@actions/exec");
const context = github.context;

const zeitToken = core.getInput("zeit-token");
const zeitTeamId = core.getInput("zeit-team-id");
const nowArgs = core.getInput("now-args");
const githubToken = core.getInput("github-token");
const githubComment = core.getInput("github-comment") === "true";
const githubDeployment = core.getInput("github-deployment") === "true";
const workingDirectory = core.getInput("working-directory");
const nowOrgId = core.getInput("now-org-id");
const nowProjectId = core.getInput("now-project-id");

const zeitAPIClient = axios.create({
baseURL: "https://api.zeit.co",
headers: {
Authorization: `Bearer ${zeitToken}`
},
params: {
teamId: zeitTeamId || undefined
}
});

let octokit;
if (githubToken) {
octokit = new github.GitHub(githubToken);
}

async function run() {
await setEnv();
await nowDeploy();
const deployment = await findPreviewUrl();
const deploymentUrl = deployment.deploymentUrl;
const deploymentCommit = deployment.deploymentCommit;
const deploymentUrl = await nowDeploy();
if (deploymentUrl) {
core.info("set preview-url output");
core.setOutput("preview-url", `https://${deploymentUrl}`);
core.setOutput("preview-url", deploymentUrl);
} else {
core.warning("get preview-url error");
}
Expand Down Expand Up @@ -91,36 +75,36 @@ async function nowDeploy() {
options.cwd = workingDirectory;
}

return await exec
.exec(
"npx",
[
"now",
...nowArgs.split(/ +/),
"-t",
zeitToken,
"-m",
`githubCommitSha=${context.sha}`,
"-m",
`githubCommitAuthorName=${context.actor}`,
"-m",
`githubCommitAuthorLogin=${context.actor}`,
"-m",
"githubDeployment=1",
"-m",
`githubOrg=${context.repo.owner}`,
"-m",
`githubRepo=${context.repo.repo}`,
"-m",
`githubCommitOrg=${context.repo.owner}`,
"-m",
`githubCommitRepo=${context.repo.repo}`,
"-m",
`githubCommitMessage=${commit}`,
],
options
)
.then(() => {});
await exec.exec(
"npx",
[
"now",
...nowArgs.split(/ +/),
"-t",
zeitToken,
"-m",
`githubCommitSha=${context.sha}`,
"-m",
`githubCommitAuthorName=${context.actor}`,
"-m",
`githubCommitAuthorLogin=${context.actor}`,
"-m",
"githubDeployment=1",
"-m",
`githubOrg=${context.repo.owner}`,
"-m",
`githubRepo=${context.repo.repo}`,
"-m",
`githubCommitOrg=${context.repo.owner}`,
"-m",
`githubCommitRepo=${context.repo.repo}`,
"-m",
`githubCommitMessage=${commit}`
],
options
);

return myOutput;
}

async function findPreviousComment(text) {
Expand All @@ -145,60 +129,6 @@ async function findPreviousComment(text) {
}
}

async function findPreviewUrl() {
let deploymentUrl;
let deploymentCommit;

const {
data: {
deployments: [commitDeployment]
}
} = await zeitAPIClient.get("/v4/now/deployments", {
params: {
"meta-githubCommitSha": context.sha
}
});

if (commitDeployment) {
deploymentUrl = commitDeployment.url;
deploymentCommit = commitDeployment.meta.githubCommitSha;
} else {
const {
data: {
deployments: [lastBranchDeployment]
}
} = await zeitAPIClient.get("/v4/now/deployments", {
params: {
"meta-githubCommitRef": context.ref
}
});

if (lastBranchDeployment) {
deploymentUrl = lastBranchDeployment.url;
deploymentCommit = lastBranchDeployment.meta.githubCommitSha;
} else {
const {
data: {
deployments: [lastDeployment]
}
} = await zeitAPIClient.get("/v4/now/deployments", {
params: {
limit: 1
}
});

if (lastDeployment) {
deploymentUrl = lastDeployment.url;
deploymentCommit = lastDeployment.meta.githubCommitSha;
}
}
}
return {
deploymentUrl: deploymentUrl,
deploymentCommit: deploymentCommit
};
}

async function createCommentOnCommit(deploymentCommit, deploymentUrl) {
if (!octokit) {
return;
Expand Down