Skip to content

Commit

Permalink
src/commands: run migrate-push by atlasaction binary (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored May 28, 2024
1 parent e086acf commit 2e8efd2
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 74 deletions.
72 changes: 50 additions & 22 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ jobs:
- checkout
- run:
name: Mock atlas with echo.sh
command: sudo cp ./src/scripts/echo.sh /bin/atlas
command: |
sudo cp ./src/scripts/echo.sh /bin/atlas
sudo cp ./src/scripts/echo.sh /bin/atlasaction
- atlas-orb/migrate_push:
working_directory: testdata
dir_name: my-cool-project
Expand All @@ -55,24 +57,22 @@ jobs:
- run:
name: Check echo.out for expected output
command: |
cat /tmp/echo.out
# Ensure "migrate push" was called twice with the expected arguments.
if [ $(grep -c "migrate push" /tmp/echo.out) -ne 2 ]
then
echo ERROR: expected two "migrate push" commands >&2
exit 1
fi
# Should include push with the git revision and latest tag.
grep -qe "my-cool-project:<< pipeline.git.revision >>" /tmp/echo.out
grep -qe "my-cool-project:latest" /tmp/echo.out
# Should include the dev URL.
grep -qe "--dev-url postgres://postgres:pass@localhost:5432/test?sslmode=disable" /tmp/echo.out
# Should include the environment.
grep -qe "--env circleci-test" /tmp/echo.out
# Should include the config.
grep -qe "--config file://atlas.hcl" /tmp/echo.out
# Should include the vars.
grep -qe "--var foo=bar --var baz=qux --var quux=corge" /tmp/echo.out
# check dir_name should be set in the environment
grep -qe "INPUT_DIR_NAME=my-cool-project" /tmp/env.out
# check tag should be set in the environment
grep -qe "INPUT_TAG=<< pipeline.git.revision >>" /tmp/env.out
# check tag latest should be set in the environment
grep -qe "INPUT_TAG=latest" /tmp/env.out
# check dir should be set in the environment
grep -qe "INPUT_DIR=file://migrations" /tmp/env.out
# check dev_url should be set in the environment
grep -qe "INPUT_DEV_URL=postgres://postgres:pass@localhost:5432/test?sslmode=disable" /tmp/env.out
# check env should be set in the environment
grep -qe "INPUT_ENV=circleci-test" /tmp/env.out
# check config should be set in the environment
grep -qe "INPUT_CONFIG=file://atlas.hcl" /tmp/env.out
# check vars should be set in the environment
grep -qe "INPUT_VARS=foo=bar baz=qux quux=corge" /tmp/env.out
command-test-migrate-lint:
executor: atlas-orb/default
steps:
Expand Down Expand Up @@ -108,6 +108,27 @@ jobs:
# check vars should be set in the environment
grep -qe "INPUT_VARS=foo=bar baz=qux quux=corge" /tmp/env.out
integration-test:
docker:
- image: cimg/base:current
- image: cimg/postgres:16.2
environment:
POSTGRES_USER: postgres
POSTGRES_DB: test
POSTGRES_PASSWORD: pass
steps:
- checkout
- atlas-orb/setup:
version: "latest"
cloud_token_env: "ATLAS_TOKEN"
- atlas-orb/migrate_lint:
working_directory: testdata
dir_name: my-cool-project
dev_url: postgres://postgres:pass@localhost:5432/test?sslmode=disable
- atlas-orb/migrate_push:
working_directory: testdata
dir_name: my-cool-project
dev_url: postgres://postgres:pass@localhost:5432/test?sslmode=disable
integration-test-gh:
docker:
- image: cimg/base:current
- image: cimg/postgres:16.2
Expand All @@ -130,7 +151,7 @@ jobs:
working_directory: testdata
dir_name: my-cool-project
dev_url: postgres://postgres:pass@localhost:5432/test?sslmode=disable
integration-test-lint:
integration-test-gh-lint:
docker:
- image: cimg/base:current
environment:
Expand Down Expand Up @@ -177,8 +198,15 @@ workflows:
- command-test-setup
- command-test-migrate-push
- command-test-migrate-lint
- integration-test-lint:
context: ariga-atlas
- integration-test-gh:
context: ariga-atlas-gh
filters: *filters
requires:
- command-test-setup
- command-test-migrate-push
- command-test-migrate-lint
- integration-test-gh-lint:
context: ariga-atlas-gh
filters: *filters
requires:
- command-test-setup
Expand Down
62 changes: 46 additions & 16 deletions src/commands/migrate_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,58 @@ parameters:
description: |
The URL of the dev-database to use for analysis. For example: mysql://root:pass@localhost:3306/dev.
Read more about [dev-databases](https://atlasgo.io/concepts/dev-database).
github_repo_env:
type: env_var_name
default: GITHUB_REPOSITORY
description: |
The repository name that linting results will be posted to.
github_token_env:
type: env_var_name
default: GITHUB_TOKEN
description: |
Environment variable containing the GitHub token.
If provided, the command will authenticate to GitHub.
(e.g. `GITHUB_TOKEN`)
steps:
- run:
name: Push migrations to Atlas Cloud
command: <<include(scripts/migrate-push.sh)>>
command: |
# replace GITHUB_REPOSITORY with the github_repo_env if provided
if [ -n "${<<parameters.github_repo_env>>}" ]; then
GITHUB_REPOSITORY=${<<parameters.github_repo_env>>}
fi
# replace GITHUB_TOKEN with the github_token_env if provided
if [ -n "${<<parameters.github_token_env>>}" ]; then
GITHUB_TOKEN=${<<parameters.github_token_env>>}
fi
atlasaction --action migrate/push
working_directory: <<parameters.working_directory>>
environment:
PARAM_DIR_NAME: <<parameters.dir_name>>
PARAM_TAG: <<parameters.tag>>
PARAM_DIR: <<parameters.dir>>
PARAM_CONFIG: <<parameters.config>>
PARAM_ENV: <<parameters.env>>
PARAM_VARS: <<parameters.vars>>
PARAM_DEV_URL: <<parameters.dev_url>>
INPUT_DIR_NAME: <<parameters.dir_name>>
INPUT_TAG: <<parameters.tag>>
INPUT_DIR: <<parameters.dir>>
INPUT_CONFIG: <<parameters.config>>
INPUT_ENV: <<parameters.env>>
INPUT_VARS: <<parameters.vars>>
INPUT_DEV_URL: <<parameters.dev_url>>
- run:
name: Push with latest tag to Atlas Cloud
command: <<include(scripts/migrate-push.sh)>>
command: |
# replace GITHUB_REPOSITORY with the github_repo_env if provided
if [ -n "${<<parameters.github_repo_env>>}" ]; then
GITHUB_REPOSITORY=${<<parameters.github_repo_env>>}
fi
# replace GITHUB_TOKEN with the github_token_env if provided
if [ -n "${<<parameters.github_token_env>>}" ]; then
GITHUB_TOKEN=${<<parameters.github_token_env>>}
fi
atlasaction --action migrate/push
working_directory: <<parameters.working_directory>>
environment:
PARAM_DIR_NAME: <<parameters.dir_name>>
PARAM_TAG: latest
PARAM_DIR: <<parameters.dir>>
PARAM_CONFIG: <<parameters.config>>
PARAM_ENV: <<parameters.env>>
PARAM_VARS: <<parameters.vars>>
PARAM_DEV_URL: <<parameters.dev_url>>
INPUT_DIR_NAME: <<parameters.dir_name>>
INPUT_TAG: latest
INPUT_DIR: <<parameters.dir>>
INPUT_CONFIG: <<parameters.config>>
INPUT_ENV: <<parameters.env>>
INPUT_VARS: <<parameters.vars>>
INPUT_DEV_URL: <<parameters.dev_url>>
36 changes: 0 additions & 36 deletions src/scripts/migrate-push.sh

This file was deleted.

0 comments on commit 2e8efd2

Please sign in to comment.