Skip to content

Commit

Permalink
Windows support (#1069)
Browse files Browse the repository at this point in the history
* update CI to inlucde Windows. Only need to test against the lowest and the highest Postgres versions

* Removing use of precompiled tasks and running postinstall script. Moved precompiled task to bin and set as a target

* make sure ameba doesn't sneak in

* ensure we use Path so they are shown correctly on Windows

* these aren't being used

* running PowerShell for Windows to do integration CLI tests

* wrong use in CI

* just trying to make this work now

* Moving CI postgres setup from container to inline runner to hopefully work on Windows

* move to env for setting shard overrides

* don't build ameba on the spec run

* specify the PG credentials for windows so it doesn't bork

* Move windows CI to experimental for now. Windows will require at least 1.14 or later to run

* removing windows CI for now until PG shard issues are resolved
  • Loading branch information
jwoertink authored Oct 20, 2024
1 parent 6922463 commit af7f877
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 55 deletions.
45 changes: 28 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,63 @@ jobs:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
shard_file:
- shard.yml
postgres_version:
- 14
- 15
- 16
crystal_version:
- 1.10.0
- latest
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
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/docs/
/lib/
/bin/*
/bin/ameba
/bin/ameba.cr
/.shards/
/tmp
/config/*.local.cr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "../../avram"
require "avram"

Gen::Migration.new.print_help_or_call(ARGV)
23 changes: 23 additions & 0 deletions script/integration_test.ps1
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 0 additions & 20 deletions script/precompile_tasks

This file was deleted.

8 changes: 2 additions & 6 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
Expand Down Expand Up @@ -51,6 +50,3 @@ development_dependencies:
lucky:
github: luckyframework/lucky
version: ">= 1.0.0"

scripts:
postinstall: BUILD_WITHOUT_DEVELOPMENT=true script/precompile_tasks
Binary file removed spec_helper
Binary file not shown.
6 changes: 3 additions & 3 deletions src/avram/tasks/gen/migration_generator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -69,15 +69,15 @@ 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
Dir.current + relative_file_path
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
Expand Down
14 changes: 7 additions & 7 deletions src/lucky/tasks/gen/resource/browser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af7f877

Please sign in to comment.