Skip to content

Commit

Permalink
src/input: support setting the config file path from the action (#59)
Browse files Browse the repository at this point in the history
* src/input: support setting the config file path from the action

* prepend url scheme

* config-env
  • Loading branch information
rotemtam authored Aug 12, 2023
1 parent 230f50b commit 0175440
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ jobs:
Configure the action by passing input parameters in the `with:` block.

#### `config-path`

Sets the path to the Atlas configuration file. By default, Atlas will
look for a file named `atlas.hcl` in the current directory.

#### `config-env`

Sets the environment to use from the Atlas configuration file.

#### `dir`

Sets the directory that contains the migration scripts to analyze.
Expand Down
10 changes: 6 additions & 4 deletions __tests__/input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ describe('input', () => {
'INPUT_CLOUD-PUBLIC': 'true',
INPUT_LATEST: '3',
'INPUT_PROJECT-ENV': 'env',
'INPUT_SKIP-CHECK-FOR-UPDATE': 'true'
'INPUT_SKIP-CHECK-FOR-UPDATE': 'true',
'INPUT_CONFIG-PATH': 'config-path'
})
const expected: Options = {
atlasVersion: 'v0.1.2',
Expand All @@ -39,8 +40,9 @@ describe('input', () => {
cloudPublic: true,
cloudURL: 'ariga-url',
latest: 3,
projectEnv: 'env',
skipCheckForUpdate: true
configEnv: 'env',
skipCheckForUpdate: true,
configPath: 'config-path'
}
expect(options).toEqual(expected)
})
Expand All @@ -63,7 +65,7 @@ describe('atlas args', () => {
test('env set', async () => {
const opts = OptionsFromEnv({
...defaultEnv,
'INPUT_PROJECT-ENV': 'test'
'INPUT_CONFIG-ENV': 'test'
})
const args = await atlasArgs(opts)
expect(args.join(' ')).toEqual('migrate lint --log {{ json . }} --env test')
Expand Down
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ inputs:
default: 'true'
required: false
project-env:
description: "The env from the atlas.hcl project file to use"
description: "The env from the atlas.hcl project file to use (Deprecated use config-env instead)"
required: false
token:
description: "GitHub token passed to the action"
default: ${{ github.token }}
skip-check-for-update:
description: 'Set true to skip check for update'
default: false
config-path:
description: 'Path to the atlas.hcl file'
required: false
config-env:
description: 'The name of the env to select in the atlas.hcl file'
required: false
runs:
using: 'node16'
main: 'dist/index.js'
18 changes: 14 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ exports.installAtlas = installAtlas;
function atlasArgs(opts) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['migrate', 'lint', '--log', '{{ json . }}'];
if (opts.projectEnv) {
args.push('--env', opts.projectEnv);
if (opts.configPath) {
args.push('--config', `file://${opts.configPath}`);
}
if (opts.configEnv) {
args.push('--env', opts.configEnv);
}
if (opts.dir) {
args.push('--dir', `file://${opts.dir}`);
Expand All @@ -70,7 +73,7 @@ function atlasArgs(opts) {
if (opts.latest && opts.latest > 0) {
args.push('--latest', opts.latest.toString());
}
if (!opts.projectEnv) {
if (!opts.configEnv) {
const gitRoot = path_1.default.resolve(yield (0, github_1.getWorkingDirectory)());
if (gitRoot) {
args.push('--git-dir', gitRoot);
Expand Down Expand Up @@ -642,8 +645,15 @@ function OptionsFromEnv(env) {
if (input('cloud-url')) {
opts.cloudURL = input('cloud-url');
}
if (input('config-path')) {
opts.configPath = input('config-path');
}
if (input('project-env')) {
opts.projectEnv = input('project-env');
(0, core_1.warning)('project-env is deprecated, use config-env instead');
opts.configEnv = input('project-env');
}
if (input('config-env')) {
opts.configEnv = input('config-env');
}
if (input('token')) {
opts.token = input('token');
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/atlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,11 @@ export async function installAtlas(opts: Options): Promise<string> {

export async function atlasArgs(opts: Options): Promise<string[]> {
const args = ['migrate', 'lint', '--log', '{{ json . }}']
if (opts.projectEnv) {
args.push('--env', opts.projectEnv)
if (opts.configPath) {
args.push('--config', `file://${opts.configPath}`)
}
if (opts.configEnv) {
args.push('--env', opts.configEnv)
}
if (opts.dir) {
args.push('--dir', `file://${opts.dir}`)
Expand All @@ -97,7 +100,7 @@ export async function atlasArgs(opts: Options): Promise<string[]> {
if (opts.latest && opts.latest > 0) {
args.push('--latest', opts.latest.toString())
}
if (!opts.projectEnv) {
if (!opts.configEnv) {
const gitRoot = path.resolve(await getWorkingDirectory())
if (gitRoot) {
args.push('--git-dir', gitRoot)
Expand Down
12 changes: 10 additions & 2 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export type Options = {
cloudToken?: string
cloudPublic?: boolean
cloudURL?: string
projectEnv?: string
configPath?: string
configEnv?: string
schemaInsights: boolean
token?: string
skipCheckForUpdate?: boolean
Expand Down Expand Up @@ -90,8 +91,15 @@ export function OptionsFromEnv(env: Dict<string>): Options {
if (input('cloud-url')) {
opts.cloudURL = input('cloud-url')
}
if (input('config-path')) {
opts.configPath = input('config-path')
}
if (input('project-env')) {
opts.projectEnv = input('project-env')
warning('project-env is deprecated, use config-env instead')
opts.configEnv = input('project-env')
}
if (input('config-env')) {
opts.configEnv = input('config-env')
}
if (input('token')) {
opts.token = input('token')
Expand Down

0 comments on commit 0175440

Please sign in to comment.