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

Publish to selected path #85

Merged
merged 19 commits into from
Mar 23, 2021
Merged
108 changes: 107 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,111 @@ jobs:
with:
name: cypress-videos-${{ runner.os }}-${{ matrix.node-version }}
path: tests/e2e/videos


multiple-versions-slash-publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Run with dest path
uses: ./
with:
jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_multiple_versions.yml"
target_branch: multiple_versions_test_pages_branch
keep_history: true
target_path: /
token: ${{ secrets.GITHUB_TOKEN }}

multiple-versions-current-publish:
runs-on: ubuntu-latest
needs: multiple-versions-slash-publish
steps:
- uses: actions/checkout@v2
with:
ref: master
- name: Run with dest path
uses: ./
with:
jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_multiple_versions.yml"
target_branch: multiple_versions_test_pages_branch
keep_history: true
target_path: current
token: ${{ secrets.GITHUB_TOKEN }}

multiple-versions-old-publish:
runs-on: ubuntu-latest
needs: multiple-versions-current-publish
steps:
- uses: actions/checkout@v2
with:
ref: test-old-version
- name: Run with dest path
uses: ./
with:
jekyll_build_options: "--config ../sample_site/_config.yml,../sample_site/_config_multiple_versions.yml"
target_branch: multiple_versions_test_pages_branch
keep_history: true
target_path: old
token: ${{ secrets.GITHUB_TOKEN }}


multiple-versions-test:
runs-on: ubuntu-latest
needs: [keep-history-test, multiple-versions-old-publish]
steps:
- name: Set the GH Pages branch
uses: actions/github-script@v3
with:
github-token: ${{secrets.JEKYLL_PAT}} # Need a PAT to switch the branch
script: |
await github.repos.updateInformationAboutPagesSite({
owner: context.repo.owner,
repo: context.repo.repo,
source: {
branch: "multiple_versions_test_pages_branch",
path: "/"
}
})
await github.repos.requestPagesBuild({
owner: context.repo.owner,
repo: context.repo.repo
})
- uses: actions/checkout@v2
- name: Caching
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Get the URL of the rendered site
id: rendered-site-url
run: |
full_url=$(curl -sH "Authorization: token ${AUTH_TOKEN}" \
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pages" | \
awk -F'"' '/\"html_url\"/ { print $4 }')
url=$(dirname "${full_url}")
echo "::set-output name=url::${url}"
env:
AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Cypress run
uses: cypress-io/github-action@v2.7.2
with:
config: baseUrl=${{ steps.rendered-site-url.outputs.url }}
working-directory: tests/e2e
spec: cypress/integration/multiple/**/*
- name: Save Cypress Screenshots
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-screenshots-${{ runner.os }}-${{ matrix.node-version }}
path: tests/e2e/screenshots
- name: Save Cypress Videos
uses: actions/upload-artifact@v2
if: always()
with:
name: cypress-videos-${{ runner.os }}-${{ matrix.node-version }}
path: tests/e2e/videos


5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ inputs:
description: 'The Jekyll Gemfile directory'
required: false
target_branch:
description: 'The target branch name the sources get pushed to'
description: 'The target branch name the site gets pushed to'
required: false
target_path:
description: 'The relative path where the site gets pushed to'
required: false
build_only:
description: 'Will build the Jekyll site without publishing it'
Expand Down
12 changes: 9 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ else
JEKYLL_SRC=$(find . -path '*/vendor/bundle' -prune -o -name '_config.yml' -exec dirname {} \;)
JEKYLL_FILES_COUNT=$(echo "$JEKYLL_SRC" | wc -l)
if [ "$JEKYLL_FILES_COUNT" != "1" ]; then
echo "::error::Found $JEKYLL_FILES_COUNT Jekyll sites! Please define which to use with input variable \"jekyll_src\""
echo "$JEKYLL_SRC"
echo "::error::Found $JEKYLL_FILES_COUNT Jekyll sites from $JEKYLL_SRC! Please define which to use with input variable \"jekyll_src\""
exit 1
fi
JEKYLL_SRC=$(echo $JEKYLL_SRC | tr -d '\n')
Expand Down Expand Up @@ -87,6 +86,13 @@ echo "::debug::Build dir is ${BUILD_DIR}"
mkdir $BUILD_DIR
cd $BUILD_DIR

if [ -n "${INPUT_TARGET_PATH}" ] && [ "${INPUT_TARGET_PATH}" != '/' ]; then
TARGET_DIR="${BUILD_DIR}/${INPUT_TARGET_PATH}"
echo "::debug::target path is set to ${INPUT_TARGET_PATH}"
else
TARGET_DIR=$BUILD_DIR
fi

if [ "${INPUT_KEEP_HISTORY}" = true ]; then
echo "::debug::Cloning ${remote_branch} from repo ${REMOTE_REPO}"
git clone --branch $remote_branch $REMOTE_REPO .
Expand Down Expand Up @@ -119,7 +125,7 @@ else
echo "::debug::Jekyll debug is off"
fi

JEKYLL_ENV=${INPUT_JEKYLL_ENV} bundle exec ${BUNDLE_ARGS} jekyll build -s ${GITHUB_WORKSPACE}/${JEKYLL_SRC} -d ${BUILD_DIR} ${INPUT_JEKYLL_BUILD_OPTIONS} ${VERBOSE}
JEKYLL_ENV=${INPUT_JEKYLL_ENV} bundle exec ${BUNDLE_ARGS} jekyll build -s ${GITHUB_WORKSPACE}/${JEKYLL_SRC} -d ${TARGET_DIR} ${INPUT_JEKYLL_BUILD_OPTIONS} ${VERBOSE}
echo "Jekyll build done"

if [ "${INPUT_BUILD_ONLY}" = true ]; then
Expand Down
2 changes: 2 additions & 0 deletions sample_site/_config_multiple_versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Jekyll AsciiDoc Action - Multiple versions
test_id: multiple
17 changes: 17 additions & 0 deletions tests/e2e/cypress/integration/multiple/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
it('works for the default branch', () => {
cy.visit('/jekyll-action/')
cy.get('#multiple').should('be.visible')
cy.get('body main div header h1').should('contain', 'Jekyll AsciiDoc Action - Multiple versions')
})

it('works for the default branch on a different path', () => {
cy.visit('/jekyll-action/current')
cy.get('#multiple').should('be.visible')
cy.get('body main div header h1').should('contain', 'Jekyll AsciiDoc Action - Multiple versions')
})

it('works for the default branch on a different path', () => {
cy.visit('/jekyll-action/old')
cy.get('#multiple').should('be.visible')
cy.get('body main div header h1').should('contain', 'Jekyll AsciiDoc Action - Multiple versions but older')
})