From b263bd649e1f8a0873c2ddad6fdaa90b7e707720 Mon Sep 17 00:00:00 2001 From: Malachi Soord Date: Sun, 3 Jul 2022 17:57:52 +0200 Subject: [PATCH] Allow override of bundler version or resolve from lock file (#114) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alain Hélaïli --- .github/workflows/test.yml | 108 +++++++++++++++++- README.md | 3 + action.yml | 3 + entrypoint.sh | 12 ++ sample_site/_config_jekyll_bundler.yml | 2 + sample_site/_config_jekyll_bundler_lock.yml | 2 + sample_site/_layouts/home.html | 2 + sample_site/_plugins/bundle_version.rb | 11 ++ .../integration/jekyll_bundler/spec.js | 7 ++ .../integration/jekyll_bundler_lock/spec.js | 7 ++ 10 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 sample_site/_config_jekyll_bundler.yml create mode 100644 sample_site/_config_jekyll_bundler_lock.yml create mode 100644 sample_site/_plugins/bundle_version.rb create mode 100644 tests/e2e/cypress/integration/jekyll_bundler/spec.js create mode 100644 tests/e2e/cypress/integration/jekyll_bundler_lock/spec.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2f9050a..26b6cd09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,9 @@ name: Testing the GitHub Pages publication on: - push + push: + branches: [master] + pull_request: concurrency: test_environment @@ -69,6 +71,108 @@ jobs: spec: cypress/integration/basic/**/* suffix: "basic" + jekyll_bundler_run: + runs-on: ubuntu-latest + outputs: + sha: ${{ steps.run.outputs.sha }} + steps: + - uses: actions/checkout@v2 + - name: Delete lock file + run: | + rm sample_site_gemfiles/Gemfile.lock + - uses: actions/cache@v2 + with: + path: sample_site_gemfiles/vendor/bundle + key: gems-${{ hashFiles('**/Gemfile') }} + restore-keys: | + gems + - name: Jekyll bundler run + id: run + uses: ./ + with: + jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_jekyll_bundler.yml" + jekyll_src: sample_site + target_branch: jekyll_bundler_test_pages_branch + jekyll_env: production + bundler_version: 2.3.11 + token: ${{secrets.JEKYLL_PAT}} + env: + JEKYLL_DEBUG: true + - name: Show used bundle version + run: | + bundle -v | cut -c 16- | xargs + cat sample_site_gemfiles/Gemfile.lock + + jekyll_bundler_publish: + runs-on: ubuntu-latest + needs: [basic_test, jekyll_bundler_run] + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/publish + with: + token: ${{ secrets.JEKYLL_PAT }} + sha: ${{ needs.jekyll_bundler_run.outputs.sha }} + branch: "jekyll_bundler_test_pages_branch" + path: "/" + + jekyll_bundler_test: + runs-on: ubuntu-latest + needs: jekyll_bundler_publish + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/test + with: + token: ${{ secrets.GITHUB_TOKEN }} + spec: cypress/integration/jekyll_bundler/**/* + suffix: "jekyll_bundler" + + jekyll_bundler_from_lock_run: + runs-on: ubuntu-latest + outputs: + sha: ${{ steps.run.outputs.sha }} + steps: + - uses: actions/checkout@v2 + - uses: actions/cache@v2 + with: + path: sample_site_gemfiles/vendor/bundle + key: gems-${{ hashFiles('**/Gemfile') }} + restore-keys: | + gems + - name: Jekyll bundler lock run + id: run + uses: ./ + with: + jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_jekyll_bundler_lock.yml" + jekyll_src: sample_site + target_branch: jekyll_bundler_lock_test_pages_branch + jekyll_env: production + token: ${{ secrets.GITHUB_TOKEN }} + env: + JEKYLL_DEBUG: true + + jekyll_bundler_from_lock_publish: + runs-on: ubuntu-latest + needs: [jekyll_bundler_test, jekyll_bundler_from_lock_run] + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/publish + with: + token: ${{ secrets.JEKYLL_PAT }} + sha: ${{ needs.jekyll_bundler_from_lock_run.outputs.sha }} + branch: "jekyll_bundler_lock_test_pages_branch" + path: "/" + + jekyll_bundler_from_lock_test: + runs-on: ubuntu-latest + needs: jekyll_bundler_from_lock_publish + steps: + - uses: actions/checkout@v2 + - uses: ./.github/actions/test + with: + token: ${{ secrets.GITHUB_TOKEN }} + spec: cypress/integration/jekyll_bundler_lock/**/* + suffix: "jekyll_bundler_lock" + jekyll_src_run: runs-on: ubuntu-latest outputs: @@ -95,7 +199,7 @@ jobs: jekyll_src_publish: runs-on: ubuntu-latest - needs: [basic_test, jekyll_src_run] + needs: [jekyll_bundler_from_lock_test, jekyll_src_run] steps: - uses: actions/checkout@v2 - uses: ./.github/actions/publish diff --git a/README.md b/README.md index 442da2bc..6d6c98d1 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,9 @@ When set to `true`, previous version of the site will be restored before the Jek keep_files: [.git, hello.html] ``` +### bundler_version +When set override the default bundler version provided. If not given will attempt to resolve bundler version from `Gemfile.lock` if one exists. + ## Use case: multi version publishing Say you want to create a documentation website where you both have the current version (`v3.0`), but also `v1.0` and `v2.0`. You can then use a combination of `keep_history` and `target_path` along with the `actions/checkout@v2`action so that each version gets pushed in a separate folder without overwritting the previous one. diff --git a/action.yml b/action.yml index 018f185a..dbcba6fe 100644 --- a/action.yml +++ b/action.yml @@ -35,6 +35,9 @@ inputs: new dependencies. For example, use `apk --update add imagemagick` to install ImageMagick. required: false + bundler_version: + description: 'When set override the default bundler version provided.' + required: false outputs: sha: description: 'Generated commit SHA1 that will be published' diff --git a/entrypoint.sh b/entrypoint.sh index cd3951fc..7ad6f917 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,11 @@ set -e echo "Starting the Jekyll Action" +if [ -n "${INPUT_BUNDLER_VERSION}" ]; then + echo "Installing bundler version specified by the user." + gem install bundler -v ${INPUT_BUNDLER_VERSION} +fi + if [ -n "$INPUT_PRE_BUILD_COMMANDS" ]; then echo "Execute pre-build commands specified by the user." eval "$INPUT_PRE_BUILD_COMMANDS" @@ -121,6 +126,13 @@ echo "::debug::Local branch is ${LOCAL_BRANCH}" cd "${GITHUB_WORKSPACE}/${GEM_SRC}" +if [ -z "${INPUT_BUNDLER_VERSION}" ] && [ -f "Gemfile.lock" ]; then + echo "Resolving bundler version from Gemfile.lock" + VERSION_LINE_NUMBER=$(($(cat Gemfile.lock | grep -n 'BUNDLED WITH' | grep -oE '\d+')+1)) + BUNDLER_VERSION=$(head -n ${VERSION_LINE_NUMBER} Gemfile.lock | tail -n 1 | xargs) + gem install bundler -v ${BUNDLER_VERSION} +fi + bundle config path "$PWD/vendor/bundle" echo "::debug::Bundle config set succesfully" bundle install diff --git a/sample_site/_config_jekyll_bundler.yml b/sample_site/_config_jekyll_bundler.yml new file mode 100644 index 00000000..e009748a --- /dev/null +++ b/sample_site/_config_jekyll_bundler.yml @@ -0,0 +1,2 @@ +title: Jekyll AsciiDoc Action - Jekyll Bundler +test_id: jekyll_bundler diff --git a/sample_site/_config_jekyll_bundler_lock.yml b/sample_site/_config_jekyll_bundler_lock.yml new file mode 100644 index 00000000..5602bf2f --- /dev/null +++ b/sample_site/_config_jekyll_bundler_lock.yml @@ -0,0 +1,2 @@ +title: Jekyll AsciiDoc Action - Jekyll Bundler Lock +test_id: jekyll_bundler_lock diff --git a/sample_site/_layouts/home.html b/sample_site/_layouts/home.html index 53109865..081cbbd6 100644 --- a/sample_site/_layouts/home.html +++ b/sample_site/_layouts/home.html @@ -10,6 +10,8 @@

{{ site.title }}

{{jekyll.environment}}

+

{{ site.bundler_version }}

+ {% include menu_item.html collection=site.data.menu.entries %} {{ content }} diff --git a/sample_site/_plugins/bundle_version.rb b/sample_site/_plugins/bundle_version.rb new file mode 100644 index 00000000..fe9f4ae6 --- /dev/null +++ b/sample_site/_plugins/bundle_version.rb @@ -0,0 +1,11 @@ +module Jekyll + + class BundleVersionGenerator < Generator + + def generate(site) + site.config['bundler_version'] = `bundle -v | cut -c 16- | xargs`.chomp + end + + end + + end diff --git a/tests/e2e/cypress/integration/jekyll_bundler/spec.js b/tests/e2e/cypress/integration/jekyll_bundler/spec.js new file mode 100644 index 00000000..2b174a59 --- /dev/null +++ b/tests/e2e/cypress/integration/jekyll_bundler/spec.js @@ -0,0 +1,7 @@ +it('works', () => { + cy.visit('/jekyll-action/') + cy.get('#jekyll_bundler').should('be.visible') + cy.get('body main div header h1').should('contain', 'Jekyll AsciiDoc Action - Jekyll Bundler') + cy.get('#env').should('contain', 'production') + cy.get('#bundlerVersion').should('contain', '2.3.11') +}) diff --git a/tests/e2e/cypress/integration/jekyll_bundler_lock/spec.js b/tests/e2e/cypress/integration/jekyll_bundler_lock/spec.js new file mode 100644 index 00000000..0e97eed5 --- /dev/null +++ b/tests/e2e/cypress/integration/jekyll_bundler_lock/spec.js @@ -0,0 +1,7 @@ +it('works', () => { + cy.visit('/jekyll-action/') + cy.get('#jekyll_bundler_lock').should('be.visible') + cy.get('body main div header h1').should('contain', 'Jekyll AsciiDoc Action - Jekyll Bundler Lock') + cy.get('#env').should('contain', 'production') + cy.get('#bundlerVersion').should('contain', '2.1.4') +})