diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index abc43d00..f43d98a7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 + diff --git a/action.yml b/action.yml index 51b8a6eb..47989415 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh index f837e5b3..6057f027 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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') @@ -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 . @@ -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 diff --git a/sample_site/_config_multiple_versions.yml b/sample_site/_config_multiple_versions.yml new file mode 100644 index 00000000..2eb2b518 --- /dev/null +++ b/sample_site/_config_multiple_versions.yml @@ -0,0 +1,2 @@ +title: Jekyll AsciiDoc Action - Multiple versions +test_id: multiple diff --git a/tests/e2e/cypress/integration/multiple/spec.js b/tests/e2e/cypress/integration/multiple/spec.js new file mode 100644 index 00000000..1328961c --- /dev/null +++ b/tests/e2e/cypress/integration/multiple/spec.js @@ -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') +})