Skip to content

Commit

Permalink
bump: @humanitec/autogen
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Jun 25, 2024
1 parent 04c3e22 commit 13e0d92
Show file tree
Hide file tree
Showing 6 changed files with 41,262 additions and 55,526 deletions.
96,595 changes: 41,214 additions & 55,381 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
117 changes: 11 additions & 106 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"author": "[email protected]",
"license": "ISC",
"type": "module",
"devDependencies": {
"@jest/globals": "^29.7.0",
"@tsconfig/node20": "^20.1.4",
Expand All @@ -29,8 +30,7 @@
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^5.1.1",
"@humanitec/autogen": "^0.0.9",
"axios": "^1.6.8",
"@humanitec/autogen": "^0.0.10",
"mustache": "^4.2.0"
},
"private": true
Expand Down
49 changes: 22 additions & 27 deletions src/action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {getOctokit, context} from '@actions/github';
import {getInput, setOutput, info, getBooleanInput} from '@actions/core';
import {render} from 'mustache';
import Mustache from 'mustache';

import {branchNameToEnvId} from './utils';
import {createApiClient, HumanitecClient} from './humanitec';
import {branchNameToEnvId} from './utils.js';
import {createApiClient, HumanitecClient} from './humanitec/index.js';
import { ResponseError } from '@humanitec/autogen';

Check failure on line 7 in src/action.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

There should be no space after '{'

Check failure on line 7 in src/action.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

There should be no space before '}'

Check failure on line 7 in src/action.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

There should be no space after '{'

Check failure on line 7 in src/action.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

There should be no space before '}'

type octokit = ReturnType<typeof getOctokit>

Expand All @@ -17,58 +18,47 @@ async function createEnvironment(input: ActionInput): Promise<void> {
const image = getInput('image') || `registry.humanitec.io/${orgId}/${imageName}`;


const baseEnvRes = await humClient.orgsOrgIdAppsAppIdEnvsEnvIdGet({
const baseEnv = await humClient.getEnvironment({
orgId,
appId,
envId: baseEnvId,
});
if (baseEnvRes.status != 200) {
throw new Error(`Unexpected response fetching env: ${baseEnvRes.status}, ${baseEnvRes.data}`);
}

const baseEnv = baseEnvRes.data;

if (!baseEnv.last_deploy) {
throw new Error(`Environment ${baseEnv.id} has never been deployed`);
}

const createEnvRes = await humClient.orgsOrgIdAppsAppIdEnvsPost(
const createEnv = await humClient.createEnvironment(
{
orgId,
appId,
environmentDefinitionRequest: {
EnvironmentDefinitionRequest: {
from_deploy_id: baseEnv.last_deploy.id,
id: envId,
name: envId,
type: baseEnv.type,
},
},
);
if (createEnvRes.status != 201) {
throw new Error(`Unexpected response creating env: ${baseEnvRes.status}, ${baseEnvRes.data}`);
}

console.log(`Created environment: ${envId}, ${environmentUrl}`);
console.log(`Created environment: ${createEnv.id}, ${environmentUrl}`);


if (createAutomationRule) {
const matchRef =`refs/heads/${branchName}`;
const createRuleRes = await humClient.orgsOrgIdAppsAppIdEnvsEnvIdRulesPost({
const createRule = await humClient.createAutomationRule({
orgId,
appId,
envId,
automationRuleRequest: {
AutomationRuleRequest: {
active: true,
artefacts_filter: [image],
type: 'update',
match_ref: matchRef,
},
});
if (createRuleRes.status != 201) {
throw new Error(`Unexpected response creating rule: ${baseEnvRes.status}, ${baseEnvRes.data}`);
}

console.log(`Created auto-deployment rule for ${matchRef} and image ${image}`);
console.log(`Created auto-deployment rule for ${createRule.match_ref} and image ${createRule.artefacts_filter[0]}`);
}


Expand Down Expand Up @@ -171,11 +161,16 @@ async function notifyDeploy(input: NotifyInput): Promise<void> {
async function deleteEnvironment(input: ActionInput): Promise<void> {
const {orgId, appId, envId, context, octokit, humClient} = input;

const delEnvRes = await humClient.orgsOrgIdAppsAppIdEnvsEnvIdDelete({
orgId, appId, envId,
});
if (delEnvRes.status != 204 && delEnvRes.status != 404) {
throw new Error(`Unexpected response creating rule: ${delEnvRes.status}, ${delEnvRes.data}`);
try {
await humClient.deleteEnvironment({
orgId, appId, envId,
});
} catch (e) {
if (e instanceof ResponseError && e.response.status == 404) {
// Environment already deleted
} else {
throw e;
}
}

console.log(`Deleted environment: ${envId}`);
Expand Down Expand Up @@ -240,7 +235,7 @@ export async function runAction(): Promise<void> {
const templateParams = {envId, appId, orgId, branchName};
let environmentUrl = webAppUrl;
if (environmentUrlTemplate) {
environmentUrl = render(environmentUrlTemplate, templateParams);
environmentUrl = Mustache.render(environmentUrlTemplate, templateParams);
}
info('Using environment: '+environmentUrl);
setOutput('environment-url', environmentUrl);
Expand Down
20 changes: 10 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as core from '@actions/core';
import {runAction} from './action';
import axios from 'axios';
import {runAction} from './action.js';
import { ResponseError } from '@humanitec/autogen';

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

There should be no space after '{'

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (20.x)

There should be no space before '}'

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

There should be no space after '{'

Check failure on line 3 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (22.x)

There should be no space before '}'

runAction().catch((e) => {
runAction().catch(async (e) => {
core.error('Action failed');

core.setFailed(`${e.name} ${e.message}`);
if (axios.isAxiosError(e)) {
if (e.config) {
core.error(`method: ${e.config.method}`);
core.error(`request: ${e.config.url}`);
}
if (e.response) {
core.error(`response: ${JSON.stringify(e.response.data)}`);

if (e instanceof ResponseError) {
const {response} = e;
core.error(`API response:`);
core.error(`status: ${response.status}`);
if (response.body && response.bodyUsed) {
core.error(`response: ${await response.text()}`);
}
}
});

0 comments on commit 13e0d92

Please sign in to comment.