diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..418236c4e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,18 @@ +name: integration +on: + schedule: + - cron: 0 2 * * 0-6 +jobs: + integration-test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@master + + - name: Build and Deploy + uses: JamesIves/github-pages-deploy-action@master + env: + ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} + BRANCH: gh-pages + FOLDER: 'test/build' + BUILD_SCRIPT: npm run-script integrationTest diff --git a/.gitignore b/.gitignore index cd01be0a5..3989b6da8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ # .DS_Store .DS_Store +.idea/ + +# Integration Tests +npm-debug.log* +yarn-debug.log* +yarn-error.log* +test/build \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 1c9344b5e..27d89633b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:10 +FROM cgr.dev/chainguard/wolfi-base:latest LABEL "com.github.actions.name"="Deploy to GitHub Pages" LABEL "com.github.actions.description"="This action will handle the building and deploying process of your project to GitHub Pages." @@ -9,5 +9,9 @@ LABEL "repository"="http://github.com/JamesIves/gh-pages-github-action" LABEL "homepage"="http://github.com/JamesIves/gh-pages-gh-action" LABEL "maintainer"="James Ives " +# Install git and bash +RUN apk update \ + && apk --no-cache add git bash + ADD entrypoint.sh /entrypoint.sh ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 607977dad..075875667 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,23 @@ +# Used By + +https://github.com/search?q=org%3Agrails+%22uses%3A+grails%2Fgithub-pages-deploy-action%22+language%3Ayml&type=code + # GitHub Pages Deploy Action :rocket: -[![View Action](https://img.shields.io/badge/view-action-blue.svg)](https://github.com/marketplace/actions/deploy-to-github-pages) [![Issues](https://img.shields.io/github/issues/JamesIves/github-pages-deploy-action.svg)](https://github.com/JamesIves/github-pages-deploy-action/issues) +[![Actions Status](https://github.com/grails/github-pages-deploy-action/workflows/integration/badge.svg)](https://github.com/grails/github-pages-deploy-action/actions) [![View Action](https://img.shields.io/badge/view-action-blue.svg)](https://github.com/marketplace/actions/deploy-to-github-pages) [![Issues](https://img.shields.io/github/issues/JamesIves/github-pages-deploy-action.svg)](https://github.com/grails/github-pages-deploy-action/issues) This [GitHub action](https://github.com/features/actions) will handle the building and deploying process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production ready code into any branch you'd like, including `gh-pages` and `docs`. This action is built on [Node](https://nodejs.org/en/), which means that you can call any optional build scripts your project requires prior to deploying. -❗️**You can find instructions for using version 1 of the GitHub Actions workflow format [here](https://github.com/JamesIves/github-pages-deploy-action/tree/1.1.3).** +❗️**You can find instructions for using version 1 of the GitHub Actions workflow format [here](https://github.com/grails/github-pages-deploy-action/tree/1.1.3).** ## Getting Started :airplane: -You can include the action in your workflow to trigger on any event that [GitHub actions](https://github.com/features/actions) supports. If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work. +You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work. You can view an example of this below. ```yml name: Build and Deploy -on: - push: - branches: - - master +on: [push] jobs: build-and-deploy: runs-on: ubuntu-latest @@ -25,12 +26,22 @@ jobs: uses: actions/checkout@master - name: Build and Deploy - uses: JamesIves/github-pages-deploy-action@master + uses: grails/github-pages-deploy-action@v2 env: ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} - BRANCH: gh-pages - FOLDER: build - BUILD_SCRIPT: npm install && npm run-script build + BASE_BRANCH: master # The branch the action should deploy from. + BRANCH: gh-pages # The branch the action should deploy to. + FOLDER: build # The folder the action should deploy. + BUILD_SCRIPT: npm install && npm run-script build # The build script the action should run prior to deploying. +``` + +If you'd like to make it so the workflow only triggers on push events to specific branches then you can modify the `on` section. You'll still need to specify a `BASE_BRANCH` if you're deploying from a branch other than `master`. + +```yml +on: + push: + branches: + - master ``` ## Configuration 📁 @@ -41,7 +52,7 @@ Below you'll find a description of what each option does. | Key | Value Information | Type | Required | | ------------- | ------------- | ------------- | ------------- | -| `ACCESS_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with a GitHub personal access token. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). This **should be stored as a secret.** | `secrets` | **Yes** | +| `ACCESS_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with a GitHub personal access token with read/write permissions. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). This **should be stored as a secret.** | `secrets` | **Yes** | | `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `env` | **Yes** | | `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. **Folder paths cannot have a leading `/` or `./`**. | `env` | **Yes** | | `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `env` | **No** | @@ -53,3 +64,25 @@ Below you'll find a description of what each option does. With the action correctly configured you should see the workflow trigger the deployment under the configured conditions. ![Example](screenshot.png) + +## Releasing a new version + +To release a new version, you need to create a new tag with the version number (prefixed with v). This can be done via +the GitHub Releases page or via the command line. +```console +git tag v3.0 +git push origin v3.0 +``` + +To make major version references work, create a new branch with the major version number (if it does not already exist). +```console +git checkout -b v3 v3.0 +git push origin v3 +``` + +When a new minor version is released, update the major version branch to point to the new release tag. +```console +git checkout v3 +git reset --hard v3.1 +git push --force origin v3 +``` \ No newline at end of file diff --git a/action.yml b/action.yml index 2de0c4b25..c2fc60902 100644 --- a/action.yml +++ b/action.yml @@ -1,4 +1,4 @@ -name: 'Deploy to GitHub Pages' +name: 'Host on GitHub Pages' description: 'This action will handle the building and deploying process of your project to GitHub Pages.' author: 'James Ives ' runs: @@ -6,4 +6,4 @@ runs: image: 'Dockerfile' branding: icon: 'git-commit' - color: 'orange' \ No newline at end of file + color: 'orange' diff --git a/entrypoint.sh b/entrypoint.sh index 5a4f52866..599a8a2d1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,8 +1,8 @@ -#!/bin/sh -l +#!/bin/bash set -e -if [ -z "$ACCESS_TOKEN" ] +if [ -z "$GH_TOKEN" ] then echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy." exit 1 @@ -14,6 +14,19 @@ then exit 1 fi +if [ -z "$DOC_FOLDER" ]; +then + DOC_FOLDER=$BRANCH +fi + +if [ -z "$SKIP_SNAPSHOT" ]; then + SKIP_SNAPSHOT="$BETA" +fi + +if [ -z "$SKIP_LATEST" ]; then + SKIP_LATEST="$SKIP_SNAPSHOT" +fi + if [ -z "$FOLDER" ] then echo "You must provide the action with the folder name in the repository where your compiled page lives." @@ -34,10 +47,10 @@ if [ -z "$COMMIT_NAME" ] then COMMIT_NAME="${GITHUB_ACTOR}" fi - -# Installs Git. -apt-get update && \ -apt-get install -y git && \ +if [ -z "$TARGET_REPOSITORY" ] +then + TARGET_REPOSITORY="${GITHUB_REPOSITORY}" +fi # Directs the action to the the Github workspace. cd $GITHUB_WORKSPACE && \ @@ -46,40 +59,106 @@ cd $GITHUB_WORKSPACE && \ git init && \ git config --global user.email "${COMMIT_EMAIL}" && \ git config --global user.name "${COMMIT_NAME}" && \ +git config --global http.version HTTP/1.1 && \ + +git config --global http.version HTTP/1.1 +git config --global http.postBuffer 157286400 ## Initializes the repository path using the access token. -REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \ +REPOSITORY_PATH="https://${GH_TOKEN}@github.com/${TARGET_REPOSITORY}.git" && \ # Checks to see if the remote exists prior to deploying. # If the branch doesn't exist it gets created here as an orphan. if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "$BRANCH" | wc -l)" -eq 0 ]; then echo "Creating remote branch ${BRANCH} as it doesn't exist..." - git checkout "${BASE_BRANCH:-master}" && \ - git checkout --orphan $BRANCH && \ - git rm -rf . && \ + mkdir $DOC_FOLDER && \ + cd $DOC_FOLDER && \ + git init && \ + git checkout -b $BRANCH && \ + git remote add origin $REPOSITORY_PATH && \ touch README.md && \ git add README.md && \ git commit -m "Initial ${BRANCH} commit" && \ git push $REPOSITORY_PATH $BRANCH +else + ## Clone the target repository + git clone "$REPOSITORY_PATH" $DOC_FOLDER --branch $BRANCH --single-branch && \ + cd $DOC_FOLDER fi -# Checks out the base branch to begin the deploy process. -git checkout "${BASE_BRANCH:-master}" && \ - # Builds the project if a build script is provided. echo "Running build scripts... $BUILD_SCRIPT" && \ eval "$BUILD_SCRIPT" && \ -if [ "$CNAME" ]; then - echo "Generating a CNAME file in in the $FOLDER directory..." - echo $CNAME > $FOLDER/CNAME +if [ -n "$CNAME" ]; then + echo "Generating a CNAME file in in the $PWD directory..." + echo $CNAME > CNAME + git add CNAME +fi + +# Update gh-pages root index page +if [ -f "../$FOLDER/ghpages.html" ]; then + cp "../$FOLDER/ghpages.html" index.html + git add index.html fi # Commits the data to Github. -echo "Deploying to GitHub..." && \ -git add -f $FOLDER && \ +if [ -z "$VERSION" ] +then + if [ -z "$SKIP_SNAPSHOT" ] || [ "$SKIP_SNAPSHOT" == "false" ]; then + echo "No Version. Publishing Snapshot of Docs" + if [ -n "${DOC_SUB_FOLDER}" ]; then + mkdir -p snapshot/$DOC_SUB_FOLDER + cp -r "../$FOLDER/." ./snapshot/$DOC_SUB_FOLDER/ + git add snapshot/$DOC_SUB_FOLDER/* + else + mkdir -p snapshot + cp -r "../$FOLDER/." ./snapshot/ + git add snapshot/* + fi + fi +else + if [ -z "$SKIP_LATEST" ] || [ "$SKIP_LATEST" == "false" ] + then + echo "Publishing Latest Docs" + if [ -n "${DOC_SUB_FOLDER}" ]; then + mkdir -p latest/$DOC_SUB_FOLDER + cp -r "../$FOLDER/." ./latest/$DOC_SUB_FOLDER/ + git add latest/$DOC_SUB_FOLDER/* + else + mkdir -p latest + cp -r "../$FOLDER/." ./latest/ + git add latest/* + fi + fi + + echo "Publishing $VERSION of Docs" + majorVersion=${VERSION:0:4} + majorVersion="${majorVersion}x" + + if [ -n "${DOC_SUB_FOLDER}" ]; then + mkdir -p "$VERSION/$DOC_SUB_FOLDER" + cp -r "../$FOLDER/." "./$VERSION/$DOC_SUB_FOLDER" + git add "$VERSION/$DOC_SUB_FOLDER/*" + else + mkdir -p "$VERSION" + cp -r "../$FOLDER/." "./$VERSION/" + git add "$VERSION/*" + fi + + if [ -n "${DOC_SUB_FOLDER}" ]; then + mkdir -p "$majorVersion/$DOC_SUB_FOLDER" + cp -r "../$FOLDER/." "./$majorVersion/$DOC_SUB_FOLDER" + git add "$majorVersion/$DOC_SUB_FOLDER/*" + else + mkdir -p "$majorVersion" + cp -r "../$FOLDER/." "./$majorVersion/" + git add "$majorVersion/*" + fi +fi + -git commit -m "Deploying to ${BRANCH} - $(date +"%T")" && \ -git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER ${BASE_BRANCH:-master}`:$BRANCH --force && \ -echo "Deployment succesful!" +git commit -m "Deploying to ${BRANCH} - $(date +"%T")" --quiet && \ +git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$TARGET_REPOSITORY.git" gh-pages || true && \ +echo "Deployment successful!" diff --git a/package.json b/package.json new file mode 100644 index 000000000..50f6c50ef --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "github-pages-deploy-action", + "description": "GitHub action for building a project and deploying it to GitHub pages.", + "license": "MIT", + "repository": "https://github.com/grails/github-pages-deploy-action", + "scripts": { + "integrationTest": "mkdir test/build && cp test/image.jpg test/build/image.jpg && cp test/index.html test/build/index.html" + } +} diff --git a/test/image.jpg b/test/image.jpg new file mode 100644 index 000000000..16bcd3d21 Binary files /dev/null and b/test/image.jpg differ diff --git a/test/index.html b/test/index.html new file mode 100644 index 000000000..024fc79a4 --- /dev/null +++ b/test/index.html @@ -0,0 +1,32 @@ + + + + + Integration Test + + + + + +
+ + \ No newline at end of file