Skip to content

Commit

Permalink
src: add dirname (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemtam authored Sep 7, 2023
1 parent 0175440 commit a3aeb56
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
4 changes: 3 additions & 1 deletion __tests__/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ describe('input', () => {
INPUT_LATEST: '3',
'INPUT_PROJECT-ENV': 'env',
'INPUT_SKIP-CHECK-FOR-UPDATE': 'true',
'INPUT_CONFIG-PATH': 'config-path'
'INPUT_CONFIG-PATH': 'config-path',
'INPUT_DIR-NAME': 'dir-name'
})
const expected: Options = {
atlasVersion: 'v0.1.2',
schemaInsights: false,
dir: 'dir',
dirFormat: 'atlas',
dirName: 'dir-name',
devUrl: 'dev-url',
cloudToken: 'ariga-token',
cloudPublic: true,
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
dir:
description: 'select migration directory relative to working directory'
required: false
dir-name:
description: 'target migration directory name (slug)'
required: false
dir-format:
description: 'Dir format for migration files ("atlas", "golang-migrate", "goose", "flyway", "liquibase", "dbmate")'
required: false
Expand Down
9 changes: 8 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,15 @@ function getMutationVariables(opts, res) {
const sourceBranch = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME;
const migrationDir = ((_a = res.summary) === null || _a === void 0 ? void 0 : _a.Env.Dir.replace('file://', '')) || '';
(0, core_1.info)(`Run metadata: ${JSON.stringify({ repository, commitID, sourceBranch, migrationDir }, null, 2)}`);
let projectName = `${repository}/${migrationDir}`;
if (opts.dirName) {
projectName = opts.dirName;
}
return {
input: {
envName: 'CI',
repo: repository,
projectName: `${repository}/${migrationDir}`,
projectName: projectName,
branch: sourceBranch !== null && sourceBranch !== void 0 ? sourceBranch : 'unknown',
commit: commitID !== null && commitID !== void 0 ? commitID : 'unknown',
url: (_j = (_e = (_d = (_c = (_b = github === null || github === void 0 ? void 0 : github.context) === null || _b === void 0 ? void 0 : _b.payload) === null || _c === void 0 ? void 0 : _c.pull_request) === null || _d === void 0 ? void 0 : _d.html_url) !== null && _e !== void 0 ? _e : (_h = (_g = (_f = github === null || github === void 0 ? void 0 : github.context) === null || _f === void 0 ? void 0 : _f.payload) === null || _g === void 0 ? void 0 : _g.repository) === null || _h === void 0 ? void 0 : _h.html_url) !== null && _j !== void 0 ? _j : 'unknown',
Expand Down Expand Up @@ -612,6 +616,9 @@ function OptionsFromEnv(env) {
if (input('dir')) {
opts.dir = input('dir');
}
if (input('dir-name')) {
opts.dirName = input('dir-name');
}
if (input('dir-format')) {
opts.dirFormat = input('dir-format');
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ function getMutationVariables(
2
)}`
)
let projectName = `${repository}/${migrationDir}`
if (opts.dirName) {
projectName = opts.dirName
}
return {
input: {
envName: 'CI',
repo: repository,
projectName: `${repository}/${migrationDir}`,
projectName: projectName,
branch: sourceBranch ?? 'unknown',
commit: commitID ?? 'unknown',
url:
Expand Down
4 changes: 4 additions & 0 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { warning } from '@actions/core'
export type Options = {
atlasVersion: string
dir?: string
dirName?: string
dirFormat?: string
devUrl?: string
latest?: number
Expand Down Expand Up @@ -58,6 +59,9 @@ export function OptionsFromEnv(env: Dict<string>): Options {
if (input('dir')) {
opts.dir = input('dir')
}
if (input('dir-name')) {
opts.dirName = input('dir-name')
}
if (input('dir-format')) {
opts.dirFormat = input('dir-format')
}
Expand Down

0 comments on commit a3aeb56

Please sign in to comment.