Skip to content

Commit

Permalink
Add github actions to build, test, and deploy automatically (#643)
Browse files Browse the repository at this point in the history
I'm adding two GitHub action workflows to automate:
* building and testing changes made to the repo
* deploying our FDT site to gh-pages whenever a release is published
  • Loading branch information
pradeepnschrodinger authored Jun 27, 2022
1 parent 169e536 commit afbc448
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .github/workflows/build-and-run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node.
# This workflow will be run whenever a new commit is pushed or when a PR is opened up.
# Guide: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Build and Run Tests

on:
# run this for every push (CI)
push:
# also run this for PR
pull_request:

jobs:
build:

runs-on: ubuntu-latest

# run this job for every combination of given matrix variables
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

steps:

# checkout our repo for the current commit
- name: Check out repo
uses: actions/checkout@v3

# setup specified node version
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile # do a clean install of all of our dependencies

# build our library to catch any build errors
- name: Build!
run: yarn run build-dist

# run all of our tests
- name: Test!
run: yarn test
81 changes: 81 additions & 0 deletions .github/workflows/deploy-gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and site, and run the deploy script.
# The deploy script will publish the build to gh-pages.
# This workflow will be run whenever a new release is published.

# NOTE (pradeep): I'm having this workflow bail out if the release doesn't target v1.2.x.
# This is because we don't have a way (yet) to support multiple FDT versions/docs be deployed at the same time,
# and hence we choose to deploy only the most stable release.

# Guide: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Deploy to gh-pages

on:
release:
types: [published]

jobs:

check-release:
name: Check if release is stable
runs-on: ubuntu-latest

# map step output to job output
outputs:
is_stable: ${{ steps.check-release-stable.outputs.is_stable }}

steps:
- name: Check if release is stable
id: check-release-stable
env:
# Store the tag name of the release in `RELEASE_TAG` (eg: v1.0.10)
RELEASE_TAG: ${{ github.event.release.tag_name }}

# Check if the release tag name is a stable candidate for deployment
# NOTE (pradeep): Only allow 1.2.x versions to be deployed right now
run: |
echo "RELEASE_TAG is: " $RELEASE_TAG
if [[ $RELEASE_TAG =~ ^v1\.2\.[0-9]+$ ]];
then
echo "This is a stable release!"
echo "::set-output name=is_stable::true"
else
echo "This is not a stable release!"
echo "::set-output name=is_stable::false"
fi
deploy:
name: Deploy website via gh-pages!
needs: check-release
runs-on: ubuntu-latest

# skip deploying to gh-pages if release is not "stable"
if: ${{ needs.check-release.outputs.is_stable == 'true' }}

steps:

# checkout our repo for the current commit
- name: Check out repo
uses: actions/checkout@v3

# setup node version 16 which is not old but still stable
- name: Use Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'yarn'

- name: Install dependencies
run: yarn install --frozen-lockfile # do a clean install of all of our dependencies

# build our static contents
- name: Build static site!
run: yarn run site-build

# publish our site to gh-pages
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }} # authenticate the action to our workflow
publish_dir: ./__site__ # this directory will be copied over to gh-pages
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"bugs": {
"url": "https://github.com/schrodinger/fixed-data-table-2/issues"
},
"homepage": "http://schrodinger.github.io/fixed-data-table-2",
"homepage": "https://schrodinger.github.io/fixed-data-table-2",
"tags": [
"react",
"table"
Expand Down

0 comments on commit afbc448

Please sign in to comment.