Skip to content

Commit

Permalink
Merge pull request #1 from kamaz/feat/build
Browse files Browse the repository at this point in the history
debug: info messages
  • Loading branch information
kamaz authored Feb 14, 2020
2 parents b9b99a5 + 446fbbd commit c158dd0
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 66 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
environmentUrl: https://github.com/features/actions
- uses: ./
with:
deploymentId: steps.deployment.outputs.deploymentId
deploymentId: ${{steps.deployment.outputs.deploymentId}}
token: ${{secrets.GITHUB_TOKEN}}
environmentUrl: https://github.com/features/actions
state: success
13 changes: 13 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,22 @@ inputs:
description: Environment url to link to
required: false
default: ''
autoMerge:
description: Auto merge
required: false
default: 'false'
transientEnvironment:
description: Transient environment
required: false
default: 'true'
productionEnvironment:
description: Production environment
required: false
default: 'false'
token:
description: Github token
required: true

outputs:
deploymentId: # id of the output
description: 'The sum of the inputs'
Expand Down
79 changes: 47 additions & 32 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const github_1 = __webpack_require__(469);
const isTrue = (value) => value === 'true';
const deploymentContext = () => {
const { owner, repo } = github_1.context.repo;
if (github_1.context.eventName === 'push') {
Expand Down Expand Up @@ -2041,47 +2042,61 @@ const deploymentContext = () => {
throw new Error(message);
}
};
const createDeploymentPayload = () => {
const { login, owner, ref, repo } = deploymentContext();
const requiredContext = core
.getInput('requiredContext')
.split(',')
.filter(x => x !== '');
const autoMerge = core.getInput('autoMerge');
const transientEnvironment = core.getInput('transientEnvironment');
const productionEnvironment = core.getInput('productionEnvironment');
return {
owner,
repo,
ref,
required_contexts: requiredContext,
payload: JSON.stringify({
user: login,
environment: 'qa',
description: 'deploying my lovely branch'
}),
environment: 'qa',
transient_environment: isTrue(transientEnvironment),
auto_merge: isTrue(autoMerge),
production_environment: isTrue(productionEnvironment)
};
};
const createDeploymentStatusPayload = (deploymentId) => {
const { owner, repo } = deploymentContext();
const state = core.getInput('state');
const environmentUrl = core.getInput('environmentUrl');
const { sha } = github_1.context;
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`;
return {
owner,
repo,
deployment_id: parseInt(deploymentId, 10),
state,
description: 'this is pr',
log_url: logUrl,
environment_url: environmentUrl
};
};
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const githubToken = core.getInput('token');
const environmentUrl = core.getInput('environmentUrl');
const requiredContext = core.getInput('requiredContext');
let deploymentId = core.getInput('deploymentId');
const octokit = new github_1.GitHub(githubToken, {});
const { login, owner, ref, repo } = deploymentContext();
if (deploymentId === '') {
const deploy = yield octokit.repos.createDeployment({
owner,
repo,
ref,
required_contexts: requiredContext.split(','),
payload: JSON.stringify({
user: login,
environment: 'qa',
description: 'deploying my lovely branch'
}),
environment: 'qa',
transient_environment: true,
auto_merge: false,
production_environment: false
});
const deploy = yield octokit.repos.createDeployment(createDeploymentPayload());
deploymentId = `${deploy.data.id}`;
core.info(`Created deployment id: ${deploymentId}`);
}
const state = core.getInput('state');
const { sha } = github_1.context;
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`;
const deploymentStatus = yield octokit.repos.createDeploymentStatus({
owner,
repo,
deployment_id: parseInt(deploymentId, 10),
state,
description: 'this is pr',
log_url: logUrl,
environment_url: environmentUrl
});
core.debug(`Created deployment status: ${deploymentStatus.data.id}`);
core.setOutput('deploymentId', new Date().toTimeString());
const deploymentStatus = yield octokit.repos.createDeploymentStatus(createDeploymentStatusPayload(deploymentId));
core.info(`Created deployment status: ${deploymentStatus.data.id}`);
core.setOutput('deploymentId', deploymentId);
}
catch (error) {
core.setFailed(error.message);
Expand Down
89 changes: 56 additions & 33 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface DeploymentContext {
login: string
}

const isTrue = (value: string): boolean => value === 'true'

const deploymentContext = (): DeploymentContext => {
const {owner, repo} = context.repo
if (context.eventName === 'push') {
Expand Down Expand Up @@ -46,52 +48,73 @@ const deploymentContext = (): DeploymentContext => {
}
}

const createDeploymentPayload = (): Octokit.ReposCreateDeploymentParams => {
const {login, owner, ref, repo} = deploymentContext()
const requiredContext = core
.getInput('requiredContext')
.split(',')
.filter(x => x !== '')
const autoMerge = core.getInput('autoMerge')
const transientEnvironment = core.getInput('transientEnvironment')
const productionEnvironment = core.getInput('productionEnvironment')

return {
owner,
repo,
ref,
required_contexts: requiredContext,
payload: JSON.stringify({
user: login,
environment: 'qa',
description: 'deploying my lovely branch'
}),
environment: 'qa',
transient_environment: isTrue(transientEnvironment),
auto_merge: isTrue(autoMerge),
production_environment: isTrue(productionEnvironment)
}
}

const createDeploymentStatusPayload = (
deploymentId: string
): Octokit.ReposCreateDeploymentStatusParams => {
const {owner, repo} = deploymentContext()
const state = core.getInput('state') as DeploymentState
const environmentUrl = core.getInput('environmentUrl')
const {sha} = context
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`
return {
owner,
repo,
deployment_id: parseInt(deploymentId, 10),
state,
description: 'this is pr',
log_url: logUrl,
environment_url: environmentUrl
}
}
async function run(): Promise<void> {
try {
const githubToken = core.getInput('token')
const environmentUrl = core.getInput('environmentUrl')
const requiredContext = core.getInput('requiredContext')
let deploymentId = core.getInput('deploymentId')

const octokit = new GitHub(githubToken, {})
const {login, owner, ref, repo} = deploymentContext()

if (deploymentId === '') {
const deploy = await octokit.repos.createDeployment({
owner,
repo,
ref,
required_contexts: requiredContext.split(','),
payload: JSON.stringify({
user: login,
environment: 'qa',
description: 'deploying my lovely branch'
}),
environment: 'qa',
transient_environment: true,
auto_merge: false,
production_environment: false
})
const deploy = await octokit.repos.createDeployment(
createDeploymentPayload()
)
deploymentId = `${deploy.data.id}`
core.info(`Created deployment id: ${deploymentId}`)
}

const state = core.getInput('state') as DeploymentState

const {sha} = context
const logUrl = `https://github.com/${owner}/${owner}/commit/${sha}/checks`
const deploymentStatus = await octokit.repos.createDeploymentStatus({
owner,
repo,
deployment_id: parseInt(deploymentId, 10),
state,
description: 'this is pr',
log_url: logUrl,
environment_url: environmentUrl
})
const deploymentStatus = await octokit.repos.createDeploymentStatus(
createDeploymentStatusPayload(deploymentId)
)

core.debug(`Created deployment status: ${deploymentStatus.data.id}`)
core.info(`Created deployment status: ${deploymentStatus.data.id}`)

core.setOutput('deploymentId', new Date().toTimeString())
core.setOutput('deploymentId', deploymentId)
} catch (error) {
core.setFailed(error.message)
}
Expand Down

0 comments on commit c158dd0

Please sign in to comment.