|
| 1 | +name: TailwindCSS integration test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + tailwindcss_integration_test: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + repository: avo-hq/avo_tailwindcss_test_repo |
| 19 | + |
| 20 | + - uses: actions/cache@v3 |
| 21 | + with: |
| 22 | + path: vendor/bundle |
| 23 | + key: ${{ runner.os }}-test-gems-${{ hashFiles('**/Gemfile.lock') }} |
| 24 | + restore-keys: | |
| 25 | + ${{ runner.os }}-test-gems-${{ hashFiles('**/Gemfile.lock') }} |
| 26 | +
|
| 27 | + - name: Set up Ruby |
| 28 | + uses: ruby/setup-ruby@v1 |
| 29 | + with: |
| 30 | + bundler: default |
| 31 | + ruby-version: 3.3.0 |
| 32 | + |
| 33 | + - name: Bundle install |
| 34 | + run: | |
| 35 | + bundle config path vendor/bundle |
| 36 | + bundle install --jobs 4 --retry 3 |
| 37 | +
|
| 38 | + - name: Set up repo |
| 39 | + run: | |
| 40 | + bin/rails app:template LOCATION='https://avohq.io/app-template' |
| 41 | + yarn init --yes |
| 42 | + bin/rails generate avo:tailwindcss:install |
| 43 | + bin/rails generate avo:tool custom_tool |
| 44 | + echo '<div class="aspect-video break-before-avoid float-end order-9 col-end-13 box-decoration-slice bg-gradient-to-r from-indigo-600 to-pink-500 text-white text-2xl font-bold">Test<br>DIV</div>' >> ./app/views/avo/tools/custom_tool.html.erb |
| 45 | + rake assets:precompile |
| 46 | +
|
| 47 | + - name: Write test file |
| 48 | + uses: DamianReeves/write-file-action@master |
| 49 | + with: |
| 50 | + path: ${{github.workspace}}/test.rb |
| 51 | + contents: | |
| 52 | + #!/usr/bin/env ruby |
| 53 | + def get_compiled_file_contents |
| 54 | + asset_name = 'avo.tailwind' |
| 55 | + compiled_assets_path = File.join(File.dirname(__FILE__), 'public', 'assets').to_s |
| 56 | +
|
| 57 | + # Find the compiled file with a matching name |
| 58 | + compiled_file = Dir[File.join(compiled_assets_path, "#{asset_name}-*")].first |
| 59 | +
|
| 60 | + # Read the contents of the file, if it exists |
| 61 | + if compiled_file |
| 62 | + File.read(compiled_file) |
| 63 | + else |
| 64 | + # Handle the case where the file is not found |
| 65 | + raise "Compiled file for '#{asset_name}' not found." |
| 66 | + end |
| 67 | + end |
| 68 | +
|
| 69 | + # Classes that are available in custom_tool.html.erb and most likely not available in the base Avo bundle |
| 70 | + test_classes = %w(aspect-video break-before-avoid float-end order-9 col-end-13 box-decoration-slice bg-gradient-to-r from-indigo-600 to-pink-500) |
| 71 | +
|
| 72 | + contents = get_compiled_file_contents |
| 73 | +
|
| 74 | + # Test if the built assets containe these classes |
| 75 | + test_classes.each do |class_name| |
| 76 | + raise "Failed to find the custom classes." unless contents.include?(class_name) |
| 77 | + end |
| 78 | + write-mode: append |
| 79 | + |
| 80 | + - name: Run test |
| 81 | + run: | |
| 82 | + ruby ${{github.workspace}}/test.rb |
0 commit comments