Skip to content

Commit

Permalink
chore(workflows): add Github actions for testing and release
Browse files Browse the repository at this point in the history
  • Loading branch information
plumdumpling committed Aug 4, 2023
1 parent 7799c6f commit 86ba04e
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
91 changes: 91 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 8
steps:
- name: Checkout repository from GitHub
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test

deploy-example:
name: Deploy example to GitHub Pages
runs-on: ubuntu-latest
steps:
- name: Checkout repository from GitHub
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build example
run: npm run build:example
- name: Deploy to GitHub Pages
run: |
git remote set-url origin https://git:${GITHUB_TOKEN}@github.com/ubilabs/react-geosuggest.git
npm run publish:example -- -u "github-actions-bot <[email protected]>"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

create-release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

publish-npm-package:
name: Publish to NPM
runs-on: ubuntu-latest
steps:
- name: Checkout repository from GitHub
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
# npm cache folder is in ~/, not within the working directory
- name: Cache npm directory
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm install
- name: Build module
run: npm run build:module
- name: Run tests
run: npm run test
- name: Publish
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_BOT_ACCESS_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run Tests

on:
push:
branches-ignore:
- main

jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 8
steps:
- name: Checkout repository from GitHub
uses: actions/checkout@v3
- name: Setup npm
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"preversion": "npm test",
"version": "npm run build:browser && npm run changelog && git add .",
"postversion": "git push && git push --tags && npm run publish:example",
"publish:example": "npm run build:example && gh-pages -d example/dist"
"publish:example": "gh-pages -d example/dist"
},
"readmeFilename": "README.md",
"keywords": [
Expand Down

0 comments on commit 86ba04e

Please sign in to comment.