From db73776567bc1c73147a8ca44905f25986c64140 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 15 Nov 2022 10:50:15 -0300 Subject: [PATCH 1/8] Address typos in CLI --- lib/html_proofer/configuration.rb | 8 ++++---- spec/html-proofer/command_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/html_proofer/configuration.rb b/lib/html_proofer/configuration.rb index ce986322..4f789ea3 100644 --- a/lib/html_proofer/configuration.rb +++ b/lib/html_proofer/configuration.rb @@ -197,12 +197,12 @@ def parse_cli_options(args) @options[long_opt_symbol] = parse_json_option("typhoeus", arg, symbolize_names: false) end - set_option(opts, "--hydra ") do |long_opt_symbol, _list| - @options[long_opt_symbol] = parse_json_option("hydra", arg, symbolize_names: false) + set_option(opts, "--hydra ") do |long_opt_symbol, arg| + @options[long_opt_symbol] = parse_json_option("hydra", arg, symbolize_names: true) end - set_option(opts, "--cache ") do |long_opt_symbol, _list| - @options[long_opt_symbol] = parse_json_option("cache", arg, symbolize_names: false) + set_option(opts, "--cache ") do |long_opt_symbol, arg| + @options[long_opt_symbol] = parse_json_option("cache", arg, symbolize_names: true) end end diff --git a/spec/html-proofer/command_spec.rb b/spec/html-proofer/command_spec.rb index 15cba4fb..12c4ac78 100644 --- a/spec/html-proofer/command_spec.rb +++ b/spec/html-proofer/command_spec.rb @@ -222,6 +222,17 @@ it "supports hydra" do http = make_bin(%(--hydra '{"max_concurrency": 5}' http://www.github.com --as-links)) expect(http.scan(/max_concurrency is invalid/).count).to(eq(0)) + expect(http.scan(/successfully/).count).to(eq(1)) + end + end + + context "when dealing with cache" do + it "basically works" do + new_time = Time.local(2022, 1, 6, 12, 0, 0) + Timecop.freeze(new_time) do + http = make_bin(%(--cache '{"timeframe": { "external": "1d"}}' http://www.github.com --as-links)) + expect(http.scan(/successfully/).count).to(eq(1)) + end end end end From 7cf2aa30db124aba93047fdd9cd53efd4ed904eb Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 15 Nov 2022 10:55:48 -0300 Subject: [PATCH 2/8] Update workflows --- .github/dependabot.yml | 22 +++++++-- .github/workflows/automerge.yml | 34 +++++++++++++ .github/workflows/lint.yml | 3 ++ .github/workflows/tag_and_release.yml | 70 +++++++++++++++++++++++++++ .github/workflows/test.yml | 8 ++- Gemfile | 2 + script/generate_changelog | 2 +- 7 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/automerge.yml create mode 100644 .github/workflows/tag_and_release.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 203f3c88..be466a31 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,20 @@ version: 2 updates: -- package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: daily + time: "09:00" + timezone: "Etc/UTC" + open-pull-requests-limit: 10 + + - package-ecosystem: "bundler" + directory: "/" + schedule: + interval: daily + time: "09:00" + timezone: "Etc/UTC" + open-pull-requests-limit: 10 + allow: + - dependency-name: "*" + dependency-type: "production" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 00000000..4b61205e --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,34 @@ +name: PR auto-{approve,merge} + +on: + pull_request_target: + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + name: Dependabot + runs-on: ubuntu-latest + + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - name: Fetch Dependabot metadata + id: dependabot-metadata + uses: dependabot/fetch-metadata@v1 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Approve Dependabot PR + if: ${{steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major'}} + run: gh pr review --approve "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Merge Dependabot PR + run: gh pr merge --auto --squash "$PR_URL" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index de67d9d6..fceb2ae9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -11,10 +11,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 with: ruby-version: 3.1 bundler-cache: true + - run: bundle install + - name: Rubocop run: bundle exec rake rubocop diff --git a/.github/workflows/tag_and_release.yml b/.github/workflows/tag_and_release.yml new file mode 100644 index 00000000..f03d530b --- /dev/null +++ b/.github/workflows/tag_and_release.yml @@ -0,0 +1,70 @@ +name: Tag and Release + +on: + workflow_dispatch: + push: + branches: + - main + paths: + - "lib/html_proofer/version.rb" + +jobs: + release: + env: + GEM_NAME: tailwind_merge + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_BOT_KEY }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up Ruby 3.1 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true + + - name: Configure Git + run: | + git config --local user.email "actions@github.com" + git config --local user.name "Actions Auto Build" + + - name: Get current version + id: version-label + run: | + VERSION=$(grep VERSION lib/html_proofer/version.rb | head -n 1 | cut -d'"' -f2) + echo "version=${VERSION}" >> $GITHUB_OUTPUT + + - name: Create tag + run: | + git tag -a v${{ steps.version-label.outputs.version }} -m "Release v${{ steps.version-label.outputs.version }}" + git push origin --tags + + - name: Generate CHANGELOG.md + id: changelog + run: script/generate_changelog + + - name: Commit & Push Changelog + run: | + git config --local user.email "actions@github.com" + git config --local user.name "Actions Auto Build" + git add -f CHANGELOG.md + git commit -m "docs: update changelog" || true + git push + + - name: Publish release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create v${{ steps.version-label.outputs.version }} --generate-notes + + - name: Publish to RubyGems + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + bundle exec rake package + for gem in pkg/html-proofer-${{ steps.version-label.outputs.version }}*.gem ; do + gem push "$gem" --host https://rubygems.org + done diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8da60b37..f3ca3e6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,6 @@ name: Test on: pull_request: - push: - branches: - - main permissions: contents: read @@ -17,14 +14,15 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Install libxslt and libxml2 - run: sudo apt-get install libxslt-dev libxml2-dev + - name: Set up Ruby 3.1 uses: ruby/setup-ruby@v1 with: ruby-version: 3.1 bundler-cache: true + - name: Install dependencies run: bundle install + - name: Run tests run: bundle exec rake diff --git a/Gemfile b/Gemfile index 6f56e044..b3c36c8c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,5 @@ source "https://rubygems.org" gemspec gem "ruby-lsp", "~> 0.3.2", group: :development + +gem "github_changelog_generator", "~> 1.16" diff --git a/script/generate_changelog b/script/generate_changelog index 8814ace5..9e75a048 100755 --- a/script/generate_changelog +++ b/script/generate_changelog @@ -1,3 +1,3 @@ #!/bin/sh -CHANGELOG_GITHUB_TOKEN="$GITHUB_CHANGELOG_TOKEN" github_changelog_generator -u gjtorikian -p html-proofer + CHANGELOG_GITHUB_TOKEN="$GITHUB_TOKEN" bundle exec github_changelog_generator -u gjtorikian -p tailwind_merge From 4ea53f81d35f772dae844beb9380ab4c142c155e Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 15 Nov 2022 10:56:32 -0300 Subject: [PATCH 3/8] :gem: bump to 5.0.2 --- lib/html_proofer/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/html_proofer/version.rb b/lib/html_proofer/version.rb index 16c3e7dc..6dcd8598 100644 --- a/lib/html_proofer/version.rb +++ b/lib/html_proofer/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module HTMLProofer - VERSION = "5.0.1" + VERSION = "5.0.2" end From 679adbae5fa2d605c06ed68efde8aea537a99e83 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Mon, 28 Nov 2022 15:24:53 -0500 Subject: [PATCH 4/8] docs: update changelog Closes https://github.com/gjtorikian/html-proofer/issues/782 --- script/generate_changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/generate_changelog b/script/generate_changelog index 9e75a048..68e614c6 100755 --- a/script/generate_changelog +++ b/script/generate_changelog @@ -1,3 +1,3 @@ #!/bin/sh - CHANGELOG_GITHUB_TOKEN="$GITHUB_TOKEN" bundle exec github_changelog_generator -u gjtorikian -p tailwind_merge + CHANGELOG_GITHUB_TOKEN="$GH_TOKEN" bundle exec github_changelog_generator -u gjtorikian -p html-proofer From bea6b3e24593add1345587fcc8c44fa2ad2a6028 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Tue, 15 Nov 2022 11:39:12 -0300 Subject: [PATCH 5/8] typos --- .github/workflows/tag_and_release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tag_and_release.yml b/.github/workflows/tag_and_release.yml index f03d530b..ace1bad5 100644 --- a/.github/workflows/tag_and_release.yml +++ b/.github/workflows/tag_and_release.yml @@ -11,7 +11,7 @@ on: jobs: release: env: - GEM_NAME: tailwind_merge + GEM_NAME: html_proofer GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_BOT_KEY }} runs-on: ubuntu-latest @@ -64,7 +64,7 @@ jobs: touch $HOME/.gem/credentials chmod 0600 $HOME/.gem/credentials printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials - bundle exec rake package + bundle exec rake build for gem in pkg/html-proofer-${{ steps.version-label.outputs.version }}*.gem ; do gem push "$gem" --host https://rubygems.org done From 931044b040149cd48f4eef519070b32b7a78fd39 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Mon, 5 Dec 2022 09:31:53 -0500 Subject: [PATCH 6/8] Fix poor srcset parsing --- lib/html_proofer/element.rb | 17 ++++++++++++++++- .../fixtures/images/base64_srcset.html | 1 + spec/html-proofer/images_spec.rb | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 spec/html-proofer/fixtures/images/base64_srcset.html diff --git a/lib/html_proofer/element.rb b/lib/html_proofer/element.rb index 5948f29d..a0bbe55c 100644 --- a/lib/html_proofer/element.rb +++ b/lib/html_proofer/element.rb @@ -82,10 +82,25 @@ def multiple_srcsets? !blank?(srcset) && srcset.split(",").size > 1 end + # From https://github.com/sindresorhus/srcset/blob/f7c48acd7facf18e94dec47e6b96e84e0f0e69dc/index.js#LL1-L16C71 + # This regex represents a loose rule of an “image candidate string”; see https://html.spec.whatwg.org/multipage/images.html#srcset-attribute + # An “image candidate string” roughly consists of the following: + # 1. Zero or more whitespace characters. + # 2. A non-empty URL that does not start or end with `,`. + # 3. Zero or more whitespace characters. + # 4. An optional “descriptor” that starts with a whitespace character. + # 5. Zero or more whitespace characters. + # 6. Each image candidate string is separated by a `,`. + # We intentionally implement a loose rule here so that we can perform more aggressive error handling and reporting in the below code. + + IMAGE_CANDIDATE_REGEX = /\s*([^,]\S*[^,](?:\s+[^,]+)?)\s*(?:,|$)/ + def srcsets return nil if blank?(srcset) - srcset.split(",").map(&:strip) + srcset.split(IMAGE_CANDIDATE_REGEX).select.with_index do |_part, idx| + idx.odd? + end.map(&:strip) end def multiple_sizes? diff --git a/spec/html-proofer/fixtures/images/base64_srcset.html b/spec/html-proofer/fixtures/images/base64_srcset.html new file mode 100644 index 00000000..4161dc97 --- /dev/null +++ b/spec/html-proofer/fixtures/images/base64_srcset.html @@ -0,0 +1 @@ + diff --git a/spec/html-proofer/images_spec.rb b/spec/html-proofer/images_spec.rb index c63813b7..e51a06ff 100644 --- a/spec/html-proofer/images_spec.rb +++ b/spec/html-proofer/images_spec.rb @@ -236,6 +236,12 @@ expect(proofer.failed_checks.first.description).to(eq("internal image /uploads/150-marie-lloyd.jpg does not exist")) end + it "supports base64 srcsets" do + relative_images = File.join(FIXTURES_DIR, "images", "base64_srcset.html") + proofer = run_proofer(relative_images, :file) + expect(proofer.failed_checks).to(eq([])) + end + it "works for images with a swapped data attribute src" do custom_data_src_check = "#{FIXTURES_DIR}/images/data_src_attribute.html" proofer = run_proofer(custom_data_src_check, :file, swap_attributes: { "img" => [["data-src", "src"]] }) From e0b9218a0a95ec3cb70853f80a838302eca88a1e Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Mon, 5 Dec 2022 09:34:01 -0500 Subject: [PATCH 7/8] :gem: bump to 5.0.3 --- lib/html_proofer/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/html_proofer/version.rb b/lib/html_proofer/version.rb index 6dcd8598..3154d0f9 100644 --- a/lib/html_proofer/version.rb +++ b/lib/html_proofer/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module HTMLProofer - VERSION = "5.0.2" + VERSION = "5.0.3" end From 39c6b7d6a5869dde8d1a1f4a5aa379b14e41fba4 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Mon, 5 Dec 2022 09:37:37 -0500 Subject: [PATCH 8/8] Fix changelog script --- script/generate_changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/generate_changelog b/script/generate_changelog index 68e614c6..6156c4c7 100755 --- a/script/generate_changelog +++ b/script/generate_changelog @@ -1,3 +1,3 @@ #!/bin/sh - CHANGELOG_GITHUB_TOKEN="$GH_TOKEN" bundle exec github_changelog_generator -u gjtorikian -p html-proofer + CHANGELOG_GITHUB_TOKEN="$GITHUB_TOKEN" bundle exec github_changelog_generator -u gjtorikian -p html-proofer