Skip to content

Commit

Permalink
added CI dependancy caching
Browse files Browse the repository at this point in the history
  • Loading branch information
tompahoward committed Nov 2, 2020
1 parent dea405c commit f50dd64
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 76 deletions.
216 changes: 141 additions & 75 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: env
- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm install
- run: npm run lint

build:
Expand All @@ -43,20 +52,28 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm install
- run: npm run build

test-node-api:
if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')"

runs-on: ubuntu-latest


strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
Expand All @@ -67,12 +84,22 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm run cover:node-api
Expand All @@ -91,12 +118,22 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm install
- run: npm run --silent json:list-github-actions-browser-matrix | sed 's/"/\\"/g' > browser-matrix.json
- run: cat browser-matrix.json
- run: echo "::set-output name=matrix::$(cat browser-matrix.json)"
Expand All @@ -110,7 +147,7 @@ jobs:

runs-on: ubuntu-latest

name: Test "${{ matrix.browser }}" on Saucy
name: Test ${{ matrix.browser }} on Saucy
strategy:
matrix:
include:
Expand All @@ -124,12 +161,22 @@ jobs:

steps:
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm install
- run: npm run cover:browser-api:${{ matrix.browser }}:saucy
env:
SAUCE_LABS_KEY: ${{secrets.SAUCE_LABS_KEY}}
Expand All @@ -149,14 +196,24 @@ jobs:
shell: bash

steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x
- run: npm config set script-shell $(which bash)
- run: npm ci
- run: npm run report:cover
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- run: npm config set script-shell $(which bash)
- run: npm install
- run: npm run report:cover


publish:
Expand All @@ -174,66 +231,75 @@ jobs:
shell: bash

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- name: Publish and Tag
run: |
npm config set script-shell $(which bash)
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(npm --unsafe-perm show "${PACKAGE_NAME}" version)
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ $CURRENT_VERSION = $PACKAGE_VERSION ]; then
echo "Version ${PACKAGE_VERSION} has already been published"
echo "PACKAGE_VERSION=" >> $GITHUB_ENV
else
npm ci
npm pack
npm run dopublish
git config user.name github-actions
git config user.email github-actions@github.com
git tag "v${PACKAGE_VERSION}"
git push --tags
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
fi
PACKAGE_NAME_WITHOUT_AT="${PACKAGE_NAME#@}"
echo "TGZ_NAME=${PACKAGE_NAME_WITHOUT_AT//\//-}" >> $GITHUB_ENV
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Create Release
if: ${{ env.PACKAGE_VERSION != '' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{ env.PACKAGE_VERSION }}
release_name: Release v${{ env.PACKAGE_VERSION }}
draft: false
prerelease: false

- name: Upload Release Asset
if: ${{ env.PACKAGE_VERSION != '' }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ env.TGZ_NAME }}-${{ env.PACKAGE_VERSION }}.tgz
asset_name: ${{ env.TGZ_NAME }}-${{ env.PACKAGE_VERSION }}.tgz
asset_content_type: application/gzip

- name: Bump Version
run: |
- uses: actions/checkout@v2

- name: Cache NPM dependencies
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-npm-cache-
- uses: actions/setup-node@v1
with:
node-version: 12.x
registry-url: https://registry.npmjs.org/
- name: Publish and Tag
run: |
npm config set script-shell $(which bash)
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION=$(npm --unsafe-perm show "${PACKAGE_NAME}" version)
PACKAGE_VERSION=$(node -p "require('./package.json').version")
if [ $CURRENT_VERSION = $PACKAGE_VERSION ]; then
echo "Version ${PACKAGE_VERSION} has already been published"
echo "PACKAGE_VERSION=" >> $GITHUB_ENV
else
npm ci
npm pack
npm run dopublish
git config user.name github-actions
git config user.email github-actions@github.com
npm --unsafe-perm --no-git-tag-version version minor -m "Version minor to %s."
git add package.json
NEXT_VERSION=$(node -p "require('./package.json').version")
git commit -m "Version bump to $NEXT_VERSION. [skip ci]"
git push origin HEAD:main
git tag "v${PACKAGE_VERSION}"
git push --tags
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
fi
PACKAGE_NAME_WITHOUT_AT="${PACKAGE_NAME#@}"
echo "TGZ_NAME=${PACKAGE_NAME_WITHOUT_AT//\//-}" >> $GITHUB_ENV
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

- name: Create Release
if: ${{ env.PACKAGE_VERSION != '' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{ env.PACKAGE_VERSION }}
release_name: Release v${{ env.PACKAGE_VERSION }}
draft: false
prerelease: false

- name: Upload Release Asset
if: ${{ env.PACKAGE_VERSION != '' }}
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ env.TGZ_NAME }}-${{ env.PACKAGE_VERSION }}.tgz
asset_name: ${{ env.TGZ_NAME }}-${{ env.PACKAGE_VERSION }}.tgz
asset_content_type: application/gzip

- name: Bump Version
run: |
git config user.name github-actions
git config user.email github-actions@github.com
npm --unsafe-perm --no-git-tag-version version minor -m "Version minor to %s."
git add package.json
NEXT_VERSION=$(node -p "require('./package.json').version")
git commit -m "Version bump to $NEXT_VERSION. [skip ci]"
git push origin HEAD:main
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ library.load(“https://api-addressr.mountain-pass.com.au”)
- [x] Firefox testing
- [x] Safari testing
- [x] fix matrix testing for UI (don't nodejs need matrix for browser tests)
- [x] dependency caching in CI pipeline
- [ ] Edge browser testing
- [ ] dependency caching in CI pipeline
- [ ] badges
- [ ] Code coverage and code quality reporting
- [ ] have pull requests from for run node-api and chrome local (nto sure how to tell if PR from fork)
Expand Down

0 comments on commit f50dd64

Please sign in to comment.