Skip to content

Commit 58c5b3d

Browse files
committed
First commit
1 parent 0ae3a4c commit 58c5b3d

File tree

3 files changed

+108
-2
lines changed

3 files changed

+108
-2
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CHANGELOG
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).
6+
7+
## [1.0.0] - 2021-08-29
8+
### Added
9+
* First release
10+
11+
### Changed
12+
* *Nothing*
13+
14+
### Deprecated
15+
* *Nothing*
16+
17+
### Removed
18+
* *Nothing*
19+
20+
### Fixed
21+
* *Nothing*

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# deploy-preview-action
2-
A github action to deploy preview environments for static apps using GitHub Pages
1+
# Deploy Preview Action
2+
3+
A GitHub action to deploy preview environments for static apps using GitHub Pages.
4+
5+
## How it works
6+
7+
This action expects you to checkout and build your static assets. After that, it will run next steps:
8+
9+
* Generate a unique slug from the branch name plus current date. For example, if your branch is `Update-landing-page`, it will generate a slug like `2021-05-08-update-landing-page`.
10+
* Publish the contents from the folder of your choice into a branch where you should have configured GitHub Pages to be served.
11+
* Use the slug generated in first step to create a sub-folder with your contents. That way, if your repository is `my-org/my-repo`, you will be able to access the preview env in https://my-org.github.io/my-repo/2021-05-08-update-landing-page
12+
* If you run this action during `pull_request` or `pull_request_target` events: publish a comment after the preview env is ready, with the URL from previous step.
13+
14+
## Usage
15+
16+
```yaml
17+
name: Build and Deploy
18+
19+
on:
20+
pull_request: null
21+
22+
jobs:
23+
build-and-deploy:
24+
runs-on: ubuntu-20.04
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v2
28+
- name: Install and Build
29+
run: |
30+
npm install
31+
npm run build
32+
33+
- name: Deploy
34+
uses: shlinkio/deploy-preview-action@v1
35+
with:
36+
branch: gh-pages # The branch from where the GitHub Pages are served (defaults to preview-env)
37+
folder: build # The folder where the artifacts to publish are (defaults to the project root)
38+
```
39+
40+
## Configuration
41+
42+
| Param | Description | Required |
43+
|----------|------------------------------------------------------------------------------------------|----------|
44+
| `branch` | The name of the branch where GitHub Pages are getting served. Defaults to `preview-env`. | No |
45+
| `folder` | The folder including the static contents to deploy. Defaults to the project root. | No |
46+
47+
## Considerations
48+
49+
* Every deployment generates a sub-folder. This action does not take care of deleting them.
50+
* Some static pages or statically generated pages expect to be served from the root of the domain. This action deploys on a sub-folder, so you may need extra steps to ensure your app works once deployed.

action.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Deploy preview
2+
description: Deploy preview environments for static apps using GitHub Pages
3+
4+
inputs:
5+
branch:
6+
description: The branch from where the GitHub Pages are served (defaults to preview-env)
7+
required: true
8+
default: 'preview-env'
9+
folder:
10+
description: The folder where the artifacts to publish are (defaults to the project root)
11+
required: true
12+
default: '.'
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Generate slug
18+
id: generate_slug
19+
run: echo "##[set-output name=slug;]$(echo ${GITHUB_HEAD_REF#refs/heads/} | sed -r 's/[~\^]+//g' | sed -r 's/[^a-zA-Z0-9]+/-/g' | sed -r 's/^-+\|-+$//g' | tr A-Z a-z)"
20+
shell: bash
21+
- name: Determine base URL
22+
id: determine_base_url
23+
run: echo "##[set-output name=base_url;]$(echo $GITHUB_REPOSITORY | sed 's/\//.github.io\//')"
24+
shell: bash
25+
- name: Deploy
26+
uses: JamesIves/github-pages-deploy-action@4.1.1
27+
with:
28+
branch: ${{ inputs.branch }}
29+
folder: ${{ inputs.folder }}
30+
target-folder: ${{ steps.generate_slug.outputs.slug }}
31+
- name: Publish env
32+
uses: marocchino/sticky-pull-request-comment@v2
33+
with:
34+
header: Preview environment
35+
message: |
36+
## Preview environment
37+
https://${{ steps.determine_base_url.outputs.base_url }}/${{ steps.generate_slug.outputs.slug }}/

0 commit comments

Comments
 (0)