atlasaction: include schema statistics in monitoring action #2144
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Go Continuous Integration | |
| on: | |
| pull_request: | |
| workflow_call: | |
| jobs: | |
| shim: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-node@v3 | |
| with: | |
| node-version: 20.x | |
| cache: "npm" | |
| cache-dependency-path: shim/package-lock.json | |
| - name: Install | |
| working-directory: shim | |
| run: | | |
| npm i | |
| npm run all | |
| - name: verify no git diff | |
| run: | | |
| status=$(git status --porcelain) | |
| if [ -n "$status" ]; then | |
| echo "you need to run 'npm run all' and commit the changes" | |
| echo "$status" | |
| exit 1 | |
| fi | |
| manifest: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - name: Run `make manifest` | |
| run: | | |
| make manifest | |
| - name: Verify no git-diff | |
| run: | | |
| status=$(git status --porcelain) | |
| if [ -n "$status" ]; then | |
| echo "you need to run 'make manifest' and commit the changes" | |
| echo "$status" | |
| exit 1 | |
| fi | |
| shim-e2e: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 0 # Disable local mode | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: ariga/setup-atlas@master | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - name: "Run Migrate Lint" | |
| uses: ./migrate/lint | |
| with: | |
| dir: file://atlasaction/testdata/migrations | |
| dev-url: sqlite://dev?mode=memory | |
| dir-name: test-dir-sqlite | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - name: "Run Migrate Push" | |
| uses: ./migrate/push | |
| with: | |
| dir: file://atlasaction/testdata/migrations | |
| dev-url: sqlite://dev?mode=memory | |
| dir-name: test-dir-sqlite | |
| golangci-lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - name: Run Go linters | |
| uses: golangci/golangci-lint-action@v3 | |
| with: | |
| args: --verbose --timeout=5m | |
| skip-pkg-cache: true | |
| unit-tests: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - name: Run tests | |
| run: go test -v -race ./... | |
| migrate-test: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - uses: ./migrate/apply | |
| with: | |
| dir: file://atlasaction/testdata/migrations | |
| url: sqlite://file.db?mode=memory | |
| - uses: ./migrate/push | |
| id: push_action | |
| with: | |
| dir: file://atlasaction/testdata/migrations | |
| dir-name: test-dir-sqlite | |
| dev-url: sqlite://file.db?mode=memory | |
| - name: "Verify migrate/push output" | |
| shell: bash | |
| run: | | |
| # Verifies that the output we got is a URL as expected | |
| [[ "${{ steps.push_action.outputs.url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]] | |
| - id: lint_success | |
| uses: ./migrate/lint | |
| with: | |
| working-directory: atlasaction/testdata | |
| dev-url: sqlite://file.db?mode=memory | |
| dir-name: test-dir-sqlite | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: lint_failure | |
| uses: ./migrate/lint | |
| continue-on-error: true | |
| with: | |
| dir: file://atlasaction/testdata/migrations_destructive | |
| dev-url: sqlite://file.db?mode=memory | |
| dir-name: test-dir-sqlite | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: check-lint-failure | |
| if: steps.lint_failure.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('lint did not when it was supposed to') | |
| - name: "Verify migrate/lint output" | |
| shell: bash | |
| run: | | |
| # Verifies that the output we got for lint tests are URLs as expected | |
| [[ "${{ steps.lint_success.outputs.report-url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]] | |
| [[ "${{ steps.lint_failure.outputs.report-url }}" =~ ^https://[a-zA-Z-]*\.atlasgo\.[a-zA-Z-]*/.*$ ]] | |
| - id: test_success | |
| uses: ./migrate/test | |
| with: | |
| dir: file://migrations | |
| working-directory: atlasaction/testdata | |
| dev-url: sqlite://file.db?mode=memory | |
| run: "expected_success" | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: test_failure | |
| uses: ./migrate/test | |
| continue-on-error: true | |
| with: | |
| working-directory: atlasaction/testdata | |
| dir: file://migrations | |
| dev-url: sqlite://file.db?mode=memory | |
| run: "expected_failure" | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: check-test-failure | |
| if: steps.test_failure.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('expected test to fail, but it did not') | |
| schema-test: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - id: test_success | |
| uses: ./schema/test | |
| with: | |
| url: file://schema.hcl | |
| working-directory: atlasaction/testdata | |
| dev-url: sqlite://file.db?mode=memory | |
| run: "expected_success" | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: test_failure | |
| uses: ./schema/test | |
| continue-on-error: true | |
| with: | |
| working-directory: atlasaction/testdata | |
| url: file://schema.hcl | |
| dev-url: sqlite://file.db?mode=memory | |
| run: "expected_failure" | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - id: check-test-failure | |
| if: steps.test_failure.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('expected test to fail, but it did not') | |
| migrate-down: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - name: mock atlas | |
| run: | | |
| cp atlasaction/mock-atlas.sh $HOME/atlas | |
| echo "$HOME" >> $GITHUB_PATH | |
| - id: pending-approval | |
| continue-on-error: true | |
| uses: ./migrate/down | |
| with: | |
| dir: file://atlasaction/testdata/down | |
| dev-url: sqlite://dev?mode=memory | |
| env: | |
| TEST_ARGS: 'migrate down --format {{ json . }} --dev-url sqlite://dev?mode=memory --context {"triggerType":"GITHUB_ACTION","triggerVersion":"v0.0.0"} --dir file://atlasaction/testdata/down' | |
| TEST_STDOUT: '{"URL":"PENDING_URL","Status":"PENDING_USER"}' | |
| TEST_EXIT_CODE: 1 | |
| - name: check-exit-code | |
| if: steps.pending-approval.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('expect to fail, but did not') | |
| - id: pending-approval-wait | |
| continue-on-error: true | |
| uses: ./migrate/down | |
| with: | |
| dir: file://atlasaction/testdata/down | |
| dev-url: sqlite://dev?mode=memory | |
| wait-timeout: 5s | |
| env: | |
| TEST_ARGS: 'migrate down --format {{ json . }} --dev-url sqlite://dev?mode=memory --context {"triggerType":"GITHUB_ACTION","triggerVersion":"v0.0.0"} --dir file://atlasaction/testdata/down' | |
| TEST_STDOUT: '{"URL":"PENDING_URL","Status":"PENDING_USER"}' | |
| TEST_EXIT_CODE: 1 | |
| - name: check-exit-code-wait | |
| if: steps.pending-approval-wait.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('expect to fail, but did not') | |
| - id: aborted | |
| continue-on-error: true | |
| uses: ./migrate/down | |
| with: | |
| dir: file://atlasaction/testdata/down | |
| dev-url: sqlite://dev?mode=memory | |
| env: | |
| TEST_ARGS: 'migrate down --format {{ json . }} --dev-url sqlite://dev?mode=memory --context {"triggerType":"GITHUB_ACTION","triggerVersion":"v0.0.0"} --dir file://atlasaction/testdata/down' | |
| TEST_STDOUT: '{"URL":"ABORTED_URL","Status":"ABORTED"}' | |
| TEST_EXIT_CODE: 1 | |
| - name: check-exit-code | |
| if: steps.aborted.outcome == 'success' | |
| uses: actions/github-script@v3 | |
| with: | |
| script: | | |
| core.setFailed('expect to fail, but did not') | |
| - id: approved | |
| uses: ./migrate/down | |
| with: | |
| dir: file://atlasaction/testdata/down | |
| dev-url: sqlite://dev?mode=memory | |
| env: | |
| TEST_ARGS: 'migrate down --format {{ json . }} --dev-url sqlite://dev?mode=memory --context {"triggerType":"GITHUB_ACTION","triggerVersion":"v0.0.0"} --dir file://atlasaction/testdata/down' | |
| TEST_STDOUT: '{"Planned":[{}],"Reverted":[{}],"Status":"APPROVED"}' | |
| - id: applied | |
| uses: ./migrate/down | |
| with: | |
| dir: file://atlasaction/testdata/down | |
| dev-url: sqlite://dev?mode=memory | |
| env: | |
| TEST_ARGS: 'migrate down --format {{ json . }} --dev-url sqlite://dev?mode=memory --context {"triggerType":"GITHUB_ACTION","triggerVersion":"v0.0.0"} --dir file://atlasaction/testdata/down' | |
| TEST_STDOUT: '{"Planned":[{}],"Reverted":[{}],"Status":"APPLIED"}' | |
| - name: verify output | |
| run: | | |
| [[ "${{ steps.pending-approval.outputs.url }}" = PENDING_URL ]] | |
| [[ "${{ steps.pending-approval-wait.outputs.url }}" = PENDING_URL ]] | |
| [[ "${{ steps.aborted.outputs.url }}" = ABORTED_URL ]] | |
| [[ "${{ steps.approved.outputs.planned_count }}" = 1 ]] | |
| [[ "${{ steps.approved.outputs.reverted_count }}" = 1 ]] | |
| [[ "${{ steps.applied.outputs.planned_count }}" = 1 ]] | |
| [[ "${{ steps.applied.outputs.reverted_count }}" = 1 ]] | |
| schema-push: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - id: sanity | |
| uses: ./schema/push | |
| with: | |
| working-directory: atlasaction/testdata/schema-apply/legacy | |
| env: test | |
| schema-plan: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event_name == 'pull_request' }} | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - id: sanity | |
| uses: ./schema/plan | |
| with: | |
| working-directory: atlasaction/testdata/schema-apply/legacy | |
| env: test | |
| from: |- | |
| env://url | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| schema-plan-approve: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| if: ${{ github.event_name == 'push' }} | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - id: sanity | |
| uses: ./schema/plan/approve | |
| with: | |
| working-directory: atlasaction/testdata/schema-apply/legacy | |
| env: test | |
| from: |- | |
| env://url | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| schema-lint: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| test: | |
| - url: sqlite://schemarule.db | |
| - url: file://ok.lt.hcl | |
| - url: file://schema.lt.hcl | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - id: schema_lint_test | |
| continue-on-error: true | |
| uses: ./schema/lint | |
| with: | |
| working-directory: atlasaction/testdata/schema-lint | |
| config: file://atlas.hcl | |
| dev-url: sqlite://file?mode=memory | |
| url: ${{ matrix.test.url }} | |
| vars: '{"rulefile":"schema.rule.hcl"}' | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| - name: Mark failure as expected | |
| if: | | |
| steps.schema_lint_test.outcome == 'failure' && | |
| matrix.test.url != 'file://ok.lt.hcl' | |
| run: echo "::notice title=Expected Failure::${{ matrix.test.url }} failed as expected" | |
| - name: Fail on unexpected failure | |
| if: | | |
| steps.schema_lint_test.outcome == 'failure' && | |
| matrix.test.url == 'file://ok.lt.hcl' | |
| run: | | |
| echo "::error title=Unexpected Failure::${{ matrix.test.url }} must pass" | |
| exit 1 | |
| schema-apply: | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| test: | |
| - directory: lint-review | |
| error: "errors or warnings were found" | |
| - directory: on-the-fly | |
| auto-approve: "true" | |
| - directory: remote-repo | |
| plan: "atlas://atlas-action/plans/20240910183610" | |
| to: "atlas://atlas-action?tag=e2e" | |
| - directory: local-plan | |
| plan: "file://20240910173744.plan.hcl" | |
| - directory: multiple-envs | |
| plan: "file://20240910173744.plan.hcl" | |
| error: "iHZMQ1EoarAXt/KU0KQbBljbbGs8gVqX2ZBXefePSGE=" | |
| - directory: legacy | |
| auto-approve: "true" | |
| version: "v0.29.0" | |
| error: "multiple pre-planned migrations were found" | |
| - directory: approval/no-changes | |
| lint-review: "ALWAYS" | |
| - directory: approval/approved | |
| lint-review: "ALWAYS" | |
| - directory: approval/pending | |
| lint-review: "ALWAYS" | |
| error: "cannot apply a migration plan in a PENDING state" | |
| - directory: approval/pending | |
| lint-review: "ALWAYS" | |
| error: "was not approved within the specified waiting period" | |
| wait-timeout: 5s | |
| - directory: approval/lint-review | |
| lint-review: "ERROR" | |
| error: "cannot apply a migration plan in a PENDING state" | |
| - directory: approval/lint-review | |
| lint-review: "ERROR" | |
| error: "was not approved within the specified waiting period" | |
| wait-timeout: 5s | |
| steps: | |
| - uses: ariga/setup-atlas@v0 | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| version: ${{ matrix.test.atlas }} | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - name: Get unix current timestamp | |
| id: timestamp | |
| run: echo "::set-output name=timestamp::$(date +%s)" | |
| - name: Apply changes | |
| continue-on-error: true | |
| id: apply_changes | |
| uses: ./schema/apply | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| CURRENT_TIMESTAMP: ${{ steps.timestamp.outputs.timestamp }} | |
| with: | |
| working-directory: atlasaction/testdata/schema-apply/${{ matrix.test.directory }} | |
| env: test | |
| plan: ${{ matrix.test.plan }} | |
| to: ${{ matrix.test.to }} | |
| auto-approve: ${{ matrix.test.auto-approve }} | |
| lint-review: ${{ matrix.test.lint-review }} | |
| wait-timeout: ${{ matrix.test.wait-timeout }} | |
| - name: Verify error | |
| if: matrix.test.error != '' | |
| shell: bash | |
| run: | | |
| # contains the error message | |
| if ! echo "${{ steps.apply_changes.outputs.error }}" | grep -q "${{ matrix.test.error }}"; then | |
| echo "Expected error: ${{ matrix.test.error }}" | |
| echo "Actual error: ${{ steps.apply_changes.outputs.error }}" | |
| exit 1 | |
| fi | |
| - name: Verify no error | |
| if: matrix.test.error == '' | |
| shell: bash | |
| run: | | |
| if [ -n "${{ steps.apply_changes.outputs.error }}" ]; then | |
| echo "Expected no error, but got: ${{steps.apply_changes.outputs.error}}" | |
| exit 1 | |
| fi | |
| monitoring: | |
| services: | |
| mysql: | |
| image: mysql:8 | |
| env: | |
| MYSQL_ROOT_PASSWORD: pass | |
| MYSQL_DATABASE: dev | |
| ports: | |
| - "3306:3306" | |
| options: >- | |
| --health-cmd "mysqladmin ping -ppass" | |
| --health-interval 10s | |
| --health-start-period 10s | |
| --health-timeout 5s | |
| --health-retries 10 | |
| runs-on: ubuntu-latest | |
| env: | |
| ATLAS_ACTION_LOCAL: 1 | |
| steps: | |
| - name: Wait for MySQL to be ready | |
| run: | | |
| for i in {1..30}; do | |
| if mysqladmin ping -h127.0.0.1 -uroot -proot --silent; then | |
| echo "MySQL is up" | |
| break | |
| fi | |
| echo "Waiting for MySQL..." | |
| sleep 1 | |
| done | |
| # views are logged in only feature in atlas | |
| - name: Create Table and View | |
| run: | | |
| echo "Creating table and view..." | |
| mysql -h 127.0.0.1 -u root --password=pass dev <<EOF | |
| CREATE TABLE users ( | |
| id INT AUTO_INCREMENT PRIMARY KEY, | |
| name VARCHAR(255) NOT NULL, | |
| email VARCHAR(255) NOT NULL | |
| ); | |
| EOF | |
| # Insert random number of rows (between 2-10) | |
| NUM_ROWS=$((RANDOM % 9 + 2)) | |
| echo "Inserting $NUM_ROWS random users..." | |
| NAMES=("Alice Johnson" "Bob Smith" "Carol White" "David Brown" "Eve Davis" "Frank Miller" "Grace Wilson" "Henry Lee" "Ivy Chen" "Jack Taylor") | |
| for i in $(seq 1 $NUM_ROWS); do | |
| NAME="${NAMES[$((i-1))]}" | |
| EMAIL=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr ' ' '.' | sed 's/$/@example.com/') | |
| mysql -h 127.0.0.1 -u root --password=pass dev -e "INSERT INTO users (name, email) VALUES ('$NAME', '$EMAIL');" | |
| done | |
| mysql -h 127.0.0.1 -u root --password=pass dev <<EOF | |
| CREATE VIEW user_emails AS | |
| SELECT id, email FROM users; | |
| EOF | |
| echo "Table and view created with $NUM_ROWS users!" | |
| - uses: ariga/setup-atlas@v0 | |
| - uses: actions/checkout@v3 | |
| - uses: actions/setup-go@v4 | |
| with: | |
| go-version-file: go.mod | |
| - run: go install ./cmd/atlas-action | |
| env: | |
| CGO_ENABLED: 0 | |
| - name: sanity using url | |
| uses: ./monitor/schema | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| url: "mysql://root:pass@localhost:3306/dev" | |
| slug: "github-action" | |
| collect-stats: "true" | |
| - name: sanity using config | |
| uses: ./monitor/schema | |
| with: | |
| cloud-token: ${{ secrets.ATLAS_TOKEN }} | |
| config: "file://monitor/schema/atlas.hcl" | |
| env: "dev" |