diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index 31710f4..99dc549 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -249,6 +249,45 @@ jobs: 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-schema-push: + executor: atlas-orb/default + steps: + - checkout + - run: + name: Mock atlas with echo.sh + command: | + sudo cp ./src/scripts/echo.sh /bin/atlas + sudo cp ./src/scripts/echo.sh /bin/atlasaction + - atlas-orb/schema_push: + working_directory: testdata + schema_name: "my-cool-project" + tag: "tag" + latest: true + url: "postgres://postgres:pass@localhost:5432/test?sslmode=disable" + dev_url: "postgres://postgres:pass@localhost:5432/dev?sslmode=disable" + env: "circleci-test" + config: "file://atlas.hcl" + vars: '{"foo": "bar", "baz": "qux", "quux": "corge"}' + - run: + name: Check echo.out for expected output + command: | + grep -qe "--action schema/push" /tmp/echo.out + # check schema_name should be set in the environment + grep -qe "INPUT_SCHEMA_NAME=my-cool-project" /tmp/env.out + # check tag should be set in the environment + grep -qe "INPUT_TAG=tag" /tmp/env.out + # check latest should be set in the environment + grep -qe "INPUT_LATEST=1" /tmp/env.out + # check url should be set in the environment + grep -qe "INPUT_URL=postgres://postgres:pass@localhost:5432/test?sslmode=disable" /tmp/env.out + # check dev_url should be set in the environment + grep -qe "INPUT_DEV_URL=postgres://postgres:pass@localhost:5432/dev?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 integration-test-versioned: docker: - image: cimg/base:current @@ -424,6 +463,34 @@ jobs: run: "expected_failure" dir: atlas://my-cool-project dev_url: postgres://postgres:pass@localhost:5432/test?sslmode=disable + integration-test-declarative-gh: + docker: + - image: cimg/base:current + - image: cimg/postgres:16.2 + environment: + POSTGRES_USER: postgres + POSTGRES_DB: test + POSTGRES_PASSWORD: pass + environment: + GITHUB_REPOSITORY: "ariga/atlas-orb" + steps: + - checkout + - run: + name: Wait for Postgres + command: dockerize -wait tcp://localhost:5432 -timeout 60s + - run: + name: Create "dev" database + command: | + psql postgres://postgres:pass@localhost:5432 -c "CREATE DATABASE dev;" + - atlas-orb/setup: + version: "latest" + cloud_token_env: "ATLAS_TOKEN" + - atlas-orb/schema_push: + working_directory: testdata/schema-push + schema_name: "circleci-schema-test" + tag: "latest" + url: "postgres://postgres:pass@localhost:5432/test?sslmode=disable" + dev_url: postgres://postgres:pass@localhost:5432/dev?sslmode=disable integration-test-declarative-gh-test: docker: - image: cimg/base:current @@ -474,6 +541,8 @@ workflows: filters: *filters - command-test-schema-test: filters: *filters + - command-test-schema-push: + filters: *filters - integration-test-versioned: context: ariga-atlas filters: *filters @@ -512,6 +581,14 @@ workflows: requires: - command-test-setup - command-test-schema-test + - command-test-schema-push + - integration-test-declarative-gh: + context: ariga-atlas-gh + filters: *filters + requires: + - command-test-setup + - command-test-schema-test + - command-test-schema-push - integration-test-declarative-gh-test: context: ariga-atlas-gh filters: *filters diff --git a/src/commands/schema_push.yml b/src/commands/schema_push.yml new file mode 100644 index 0000000..408fcbc --- /dev/null +++ b/src/commands/schema_push.yml @@ -0,0 +1,65 @@ +description: > + Push a schema to [Atlas Registry](https://atlasgo.io/registry) with an optional tag. + +parameters: + schema_name: + type: string + default: '' + description: | + The name (slug) of the schema repository in [Atlas Registry](https://atlasgo.io/registry). + tag: + type: string + default: '' + description: | + The tag to apply to the pushed schema. By default, the current git commit hash is used. + latest: + type: boolean + default: false + description: | + If true, the pushed schema will be tagged as `latest`. + dev_url: + type: string + default: '' + 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). + url: + type: string + default: '' + description: | + The desired schema URL(s) to test. For Example: `file://schema.hcl` + config: + type: string + default: '' + description: | + The path to the Atlas configuration file. By default, Atlas will look for a file named `atlas.hcl` in the current directory. + For example, `file://config/atlas.hcl`. Learn more about [Atlas configuration files](https://atlasgo.io/atlas-schema/projects). + vars: + type: string + default: '' + description: | + Stringify JSON object containing variables to be used inside the Atlas configuration file. For example: '{"var1": "value1", "var2": "value2"}' + working_directory: + type: string + default: "." + description: | + The working directory to run from. Defaults to project root. + env: + type: string + default: '' + description: | + The environment to use from the Atlas configuration file. For example, `dev`. +steps: + - run: + name: Test schema on a database + working_directory: <> + command: atlasaction --action schema/push + environment: + INPUT_SCHEMA_NAME: <> + INPUT_TAG: <> + INPUT_LATEST: <> + INPUT_DEV_URL: <> + INPUT_URL: <> + INPUT_CONFIG: <> + INPUT_ENV: <> + INPUT_VARS: <>