From a2ef6b0e494241461ffc6e9cc4fd6c9c03c742e6 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Wed, 24 Jan 2024 10:56:17 -0500 Subject: [PATCH 1/4] Add build and deployment workflows. --- .github/workflows/build-deploy.yml | 64 ++++++++++++++++++++++++++++++ .github/workflows/build.yml | 56 ++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 .github/workflows/build-deploy.yml create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml new file mode 100644 index 0000000..9c47547 --- /dev/null +++ b/.github/workflows/build-deploy.yml @@ -0,0 +1,64 @@ +name: Build and Deploy + +on: + push: + branches: + main + +jobs: + build: + if: ${{ github.repository_owner == 'cosmicds' }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + persist-credentials: false + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.17.1' + + - name: Yarn install + run: yarn install + + - name: Lint + run: yarn lint + + - name: Build + run: yarn build + + # - name: BrowserStack env setup + # uses: browserstack/github-actions/setup-env@master + # with: + # username: ${{ secrets.BROWSERSTACK_USERNAME }} + # access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + + # - name: BrowserStack local tunnel setup + # uses: browserstack/github-actions/setup-local@master + # with: + # local-testing: start + # local-identifier: random + + # - name: Run BrowserStack tests + # run: | + # set -xeuo pipefail + # yarn serve & + # sleep 10 + # yarn test-bslocal -e default,firefox,edge,safari -o reports + + - name: Check for draft flag + uses: sergeysova/jq-action@v2 + id: draft + with: + cmd: cat package.json | jq -r '.draft // false' + + - name: Deploy to GitHub Pages + uses: JamesIves/github-pages-deploy-action@v4 + if: ${{ steps.draft.outputs.value }} == 'true' + with: + branch: gh-pages + folder: dist + ssh-key: ${{ secrets.DEPLOY_KEY }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5f3bb56 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,56 @@ +name: Build + +on: + pull_request_target: + branches: + main + +permissions: read-all + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + persist-credentials: false + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18.17.1' + + - name: Yarn install + run: yarn install + + - name: Lint + run: yarn lint + + - name: Build + run: yarn build + + # - name: BrowserStack env setup + # uses: browserstack/github-actions/setup-env@master + # with: + # username: ${{ secrets.BROWSERSTACK_USERNAME }} + # access-key: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + + # - name: 'BrowserStack local tunnel setup' + # uses: browserstack/github-actions/setup-local@master + # with: + # local-testing: start + # local-identifier: random + + # - name: Run BrowserStack tests + # run: | + # set -xeuo pipefail + # yarn serve & + # sleep 10 + # yarn test-bslocal -e default,firefox,edge,safari -o reports + + # - name: 'BrowserStackLocal Stop' # Terminating the BrowserStackLocal tunnel connection + # uses: browserstack/github-actions/setup-local@master + # with: + # local-testing: stop From b5f55832a1ef449dc5f65949f283ee815e9041af Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Wed, 24 Jan 2024 11:03:15 -0500 Subject: [PATCH 2/4] Update README with information about workflows and Github Actions/Pages. --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 78b8678..101ac5a 100644 --- a/README.md +++ b/README.md @@ -21,10 +21,12 @@ If you get complaints that the script isn't executable, make it so by running `c - To preview the story using the development server, run `yarn serve` - To build the story for production use, run `yarn build` -## Deployment +## Deployment and Github Actions -The built story is just a set of HTML/CSS/JS + any assets that you add, so it should be easy to host anywhere. One simple way to host a story is using Github Pages, which provides a free static site hosting service for public repositories. This can even be done automatically using Github Actions - see the `build-deploy` in the [Carina data story](https://github.com/cosmicds/carinads) for an example. +The built story is just a set of HTML/CSS/JS + any assets that you add, so it should be easy to host anywhere. One simple way to host a story is using Github Pages, which provides a free static site hosting service for public repositories. This repository provides two workflows (see the `.github/workflows` directory) to help with this: +* `build.yml` - on a pull request, build the PR version of the story (to test that it at least builds successfully) +* `build-deploy.yml` - on a commit to main, build the story and push the built version to the `gh-pages` branch. This built version can then be deployed to Github Pages in the repository settings: `Settings > Pages`, then choose `Deploy from a branch` and use the `gh-pages` branch. ## BrowserStack testing - CosmicDS team -If you're a member of the CosmicDS team, we can perform E2E testing (both locally and in Github Actions) using BrowserStack. See the tests in the [Carina data story](https://github.com/cosmicds/carinads) as an example. Note that you'll need to have our BrowserStack username and access key for this to work correctly. +If you're a member of the CosmicDS team, we can perform E2E testing (both locally and in Github Actions) using BrowserStack. To activate this testing, uncomment the relevant pieces in the provided workflows. Note that you'll need to have our BrowserStack username and access key for this to work correctly. (If the repository that you're working on is part of the CosmicDS organization, you shouldn't need to add these at the repository level). From fd51cd1dd419cc19f27bc24a64e62f791093d4c8 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Wed, 24 Jan 2024 11:07:10 -0500 Subject: [PATCH 3/4] Update some naming in the setup script and index.html. --- public/index.html | 9 ++++----- scripts/setup.sh | 19 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/public/index.html b/public/index.html index cf0c8db..32b77ef 100644 --- a/public/index.html +++ b/public/index.html @@ -16,10 +16,9 @@ - - - + + + @@ -31,7 +30,7 @@ - MiniDS Template + CosmicDS Template diff --git a/scripts/setup.sh b/scripts/setup.sh index 8df019e..a65edec 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -13,7 +13,7 @@ function space_split_pascal { } if [[ $# -lt 1 ]]; then - echo "Mini name is missing!" + echo "Story name is missing!" exit 2 fi if [[ $# -gt 1 ]]; then @@ -23,23 +23,22 @@ fi name=$1 -if [[ -d $name ]] | [[ -h $name ]]; then - echo "A directory for this mini already exists!" - exit 2 -fi - -node scripts/update-name.js "@minids/${name}" +node scripts/update-name.js "@cosmicds/${name}" pascal_case_name=$(to_pascal_case $name) title=$(space_split_pascal ${pascal_case_name}) cd src sed -i.bak "s/MainComponent/${pascal_case_name}/g" main.ts -sed -i.bak "s/wwt-minids-template/wwt-minids-$name/g" main.ts +sed -i.bak "s/wwt-minids-template/$name/g" main.ts rm -f main.ts.bak mv MainComponent.vue ${pascal_case_name}.vue cd ../public sed -i.bak "s/minids-template/$name/g" index.html -sed -i.bak "s/MiniDS data story template/$pascal_case_name/g" index.html -sed -i.bak "s/MiniDS Template/$title/g" index.html +sed -i.bak "s/CosmicDS data story template/$pascal_case_name/g" index.html +sed -i.bak "s/CosmicDS Template/$title/g" index.html rm -f index.html.bak + +# Clear out git info since we don't want this to point to the vue-ds-template repo anymore +cd .. +rm -r .git From da7aa934ae219d3cab111f499f9dba9c611294a0 Mon Sep 17 00:00:00 2001 From: Carifio24 Date: Wed, 24 Jan 2024 11:09:43 -0500 Subject: [PATCH 4/4] Force-remove git directory to avoid prompts. --- scripts/setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index a65edec..d6792da 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -41,4 +41,4 @@ rm -f index.html.bak # Clear out git info since we don't want this to point to the vue-ds-template repo anymore cd .. -rm -r .git +rm -rf .git