diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8714a8972..fd7d35f94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,11 +29,12 @@ jobs: strategy: fail-fast: false matrix: + os: + - ubuntu-latest shard_file: - shard.yml postgres_version: - 14 - - 15 - 16 crystal_version: - 1.10.0 @@ -41,40 +42,50 @@ jobs: experimental: - false include: + # NOTE: PG shard does not compile on Windows https://github.com/will/crystal-pg/issues/291 + # Until that's resolved, this will always fail, so leaving this commented out for now + # - shard_file: shard.yml + # crystal_version: latest + # postgres_version: 16 + # experimental: true + # os: windows-latest - shard_file: shard.edge.yml crystal_version: latest postgres_version: 14 experimental: true + os: ubuntu-latest - shard_file: shard.override.yml crystal_version: nightly postgres_version: 14 experimental: true - runs-on: ubuntu-latest + os: ubuntu-latest + runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} - services: - postgres: - image: postgres:${{ matrix.postgres_version }}-alpine - env: - POSTGRES_USER: lucky - POSTGRES_PASSWORD: developer - ports: - - 5432:5432 - # needed because the postgres container does not provide a healthcheck - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - uses: actions/checkout@v4 - - name: Setup PostgreSQL Client v${{ matrix.postgres_version }} - uses: tj-actions/install-postgresql@v3 + - name: Setup PostgreSQL v${{ matrix.postgres_version }} + uses: ikalnytskyi/action-setup-postgres@v6 with: - postgresql-version: ${{ matrix.postgres_version }} + username: lucky + password: developer + port: 5432 + postgres-version: ${{ matrix.postgres_version }} - uses: crystal-lang/install-crystal@v1 with: crystal: ${{matrix.crystal_version}} - name: Install shards - run: SHARDS_OVERRIDE=${{ matrix.shard_file }} shards install - - name: Run integration test + run: shards install --skip-postinstall --skip-executables + env: + SHARDS_OVERRIDE: ${{ matrix.shard_file }} + - name: Run integration test (Linux) run: ./script/integration_test + if: matrix.os == 'ubuntu-latest' + env: + DATABASE_URL: postgres://lucky:developer@localhost:5432/avram_dev + - name: Run integration test (Windows) + run: .\script\integration_test.ps1 + if: matrix.os == 'windows-latest' env: DATABASE_URL: postgres://lucky:developer@localhost:5432/avram_dev - name: Run tests diff --git a/.gitignore b/.gitignore index a82f3951a..5eb9a8cb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /docs/ /lib/ -/bin/* +/bin/ameba +/bin/ameba.cr /.shards/ /tmp /config/*.local.cr diff --git a/src/precompiled_tasks/gen/migration.cr b/bin/lucky.gen.migration.cr similarity index 67% rename from src/precompiled_tasks/gen/migration.cr rename to bin/lucky.gen.migration.cr index 250e3bbcb..2b575bc4f 100644 --- a/src/precompiled_tasks/gen/migration.cr +++ b/bin/lucky.gen.migration.cr @@ -1,3 +1,3 @@ -require "../../avram" +require "avram" Gen::Migration.new.print_help_or_call(ARGV) diff --git a/script/integration_test.ps1 b/script/integration_test.ps1 new file mode 100644 index 000000000..e476cef2b --- /dev/null +++ b/script/integration_test.ps1 @@ -0,0 +1,23 @@ +# Exit if any subcommand fails +$ErrorActionPreferences = "Stop" + +Write-Host "\nRunning tasks\n\n" + +crystal tasks.cr db.drop +crystal tasks.cr db.create +crystal tasks.cr db.migrate + +# If there were no errors, continue the test +if ($?) { + # Integration test various tasks + Write-Host "\nRolling back to 20180802180356\n" + crystal tasks.cr db.rollback_to 20180802180356 + crystal tasks.cr db.migrations.status + Write-Host "\nRolling back remainder\n" + crystal tasks.cr db.rollback_all + crystal tasks.cr db.migrate.one + crystal tasks.cr db.migrate + crystal tasks.cr db.reset + crystal tasks.cr db.drop + crystal tasks.cr db.setup +} diff --git a/script/precompile_tasks b/script/precompile_tasks deleted file mode 100755 index f5e548c7b..000000000 --- a/script/precompile_tasks +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Exit if any subcommand fails -set -e - -# Precompile tasks if not in production and not in CI -# Also allow skipping precompilation with an ENV var -if [ "$LUCKY_ENV" != "production" ] && [ -z "$CI" ] && [ -z "$SKIP_LUCKY_TASK_PRECOMPILATION" ]; then - # This is to prevent Avram's development dependencies being installed - # from an external source like running `shards install` from a Lucky app. - # Install shards and build shard targets. - if [ -z "$BUILD_WITHOUT_DEVELOPMENT" ]; then - shards build - else - shards build --without-development - fi - - mkdir -p ../../bin - cp -r "$PWD/bin" "$PWD/../.." -fi diff --git a/shard.yml b/shard.yml index 6ac13bdd5..d31fae2c0 100644 --- a/shard.yml +++ b/shard.yml @@ -5,9 +5,8 @@ crystal: ">= 1.10.0" license: MIT -targets: - lucky.gen.migration: - main: src/precompiled_tasks/gen/migration.cr +executables: + - lucky.gen.migration.cr authors: - Paul Smith @@ -51,6 +50,3 @@ development_dependencies: lucky: github: luckyframework/lucky version: ">= 1.0.0" - -scripts: - postinstall: BUILD_WITHOUT_DEVELOPMENT=true script/precompile_tasks diff --git a/spec_helper b/spec_helper deleted file mode 100755 index b61603b2c..000000000 Binary files a/spec_helper and /dev/null differ diff --git a/src/avram/tasks/gen/migration_generator.cr b/src/avram/tasks/gen/migration_generator.cr index d5cdfe096..00009743d 100644 --- a/src/avram/tasks/gen/migration_generator.cr +++ b/src/avram/tasks/gen/migration_generator.cr @@ -52,7 +52,7 @@ class Avram::Migrator::MigrationGenerator end private def ensure_unique - d = Dir.new(Dir.current + "/db/migrations") + d = Dir.new(Dir.current + Path["/db/migrations"].to_s) d.each_child { |x| if x.starts_with?(/[0-9]{14}_#{name.underscore}.cr/) raise <<-ERROR @@ -69,7 +69,7 @@ class Avram::Migrator::MigrationGenerator end private def make_migrations_folder_if_missing - FileUtils.mkdir_p Dir.current + "/db/migrations" + FileUtils.mkdir_p Dir.current + Path["/db/migrations"].to_s end private def file_path @@ -77,7 +77,7 @@ class Avram::Migrator::MigrationGenerator end private def relative_file_path - "/db/migrations/#{version}_#{name.underscore}.cr" + Path["/db/migrations/#{version}_#{name.underscore}.cr"].to_s end private def version diff --git a/src/lucky/tasks/gen/resource/browser.cr b/src/lucky/tasks/gen/resource/browser.cr index 17cf7b6fb..73d0c215e 100644 --- a/src/lucky/tasks/gen/resource/browser.cr +++ b/src/lucky/tasks/gen/resource/browser.cr @@ -98,23 +98,23 @@ class Gen::Resource::Browser < LuckyTask::Task end private def display_success_messages - success_message(resource_name, "./src/models/#{underscored_resource}.cr") - success_message("Save" + resource_name, "./src/operations/save_#{underscored_resource}.cr") - success_message("Delete" + resource_name, "./src/operations/delete_#{underscored_resource}.cr") - success_message(resource_name + "Query", "./src/queries/#{underscored_resource}_query.cr") + success_message(resource_name, Path["./src/models/#{underscored_resource}.cr"].to_s) + success_message("Save" + resource_name, Path["./src/operations/save_#{underscored_resource}.cr"].to_s) + success_message("Delete" + resource_name, Path["./src/operations/delete_#{underscored_resource}.cr"].to_s) + success_message(resource_name + "Query", Path["./src/queries/#{underscored_resource}_query.cr"].to_s) %w(index show new create edit update delete).each do |action| success_message( pluralized_name + "::" + action.capitalize, - "./src/actions/#{folder_name}/#{action}.cr" + Path["./src/actions/#{folder_name}/#{action}.cr"].to_s ) end %w(index show new edit).each do |action| success_message( pluralized_name + "::" + action.capitalize + "Page", - "./src/pages/#{folder_name}/#{action}_page.cr" + Path["./src/pages/#{folder_name}/#{action}_page.cr"].to_s ) end - success_message("#{pluralized_name}::FormFields", "./src/components/#{folder_name}/form_fields.cr") + success_message("#{pluralized_name}::FormFields", Path["./src/components/#{folder_name}/form_fields.cr"].to_s) end private def underscored_resource