Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Allow override of bundler version or resolve from lock file (#114)
Browse files Browse the repository at this point in the history
Co-authored-by: Alain Hélaïli <helaili@github.com>
  • Loading branch information
inverse and helaili authored Jul 3, 2022
1 parent 8db04b1 commit b263bd6
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 2 deletions.
108 changes: 106 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: Testing the GitHub Pages publication

on:
push
push:
branches: [master]
pull_request:

concurrency: test_environment

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sample_site/_config_jekyll_bundler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Jekyll AsciiDoc Action - Jekyll Bundler
test_id: jekyll_bundler
2 changes: 2 additions & 0 deletions sample_site/_config_jekyll_bundler_lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Jekyll AsciiDoc Action - Jekyll Bundler Lock
test_id: jekyll_bundler_lock
2 changes: 2 additions & 0 deletions sample_site/_layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ <h1 id={{ site.test_id }}>{{ site.title }}</h1>

<h2 id="env">{{jekyll.environment}}</h2>

<h2 id="bundlerVersion">{{ site.bundler_version }}</h2>

{% include menu_item.html collection=site.data.menu.entries %}

{{ content }}
11 changes: 11 additions & 0 deletions sample_site/_plugins/bundle_version.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/e2e/cypress/integration/jekyll_bundler/spec.js
Original file line number Diff line number Diff line change
@@ -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')
})
7 changes: 7 additions & 0 deletions tests/e2e/cypress/integration/jekyll_bundler_lock/spec.js
Original file line number Diff line number Diff line change
@@ -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')
})

0 comments on commit b263bd6

Please sign in to comment.