Skip to content

Commit

Permalink
ci: CI setup
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 5, 2023
1 parent 663cb2a commit 9bc00cc
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 0 deletions.
187 changes: 187 additions & 0 deletions .github/workflows/integrate.yml
@@ -0,0 +1,187 @@
# master only

name: Integrate

on:
push:
branches: [master]

env:
SLS_IGNORE_WARNING: "*"
FORCE_COLOR: 1

jobs:
linuxNode16:
name: "[Linux] Node.js v16: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v16-${{ runner.os }}-${{ github.ref }}-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test

linuxNode18:
name: "[Linux] Node.js v18: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v18-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v18-${{ runner.os }}-${{ github.ref }}-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 17.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test

linuxNode14:
name: "[Linux] Node.js v14: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v14-${{ runner.os }}-${{ github.ref }}-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test

linuxNode12:
name: "[Linux] Node.js v12: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v12-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v12-${{ runner.os }}-${{ github.ref }}-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test

linuxNode10:
name: "[Linux] Node.js v10: Unit tests"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
id: cacheNpm
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v10-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
restore-keys: npm-v10-${{ runner.os }}-${{ github.ref }}-

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 10.x

- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Unit tests
run: npm test

tagIfNewVersion:
name: Tag if new version
runs-on: ubuntu-latest
needs: [linuxNode16, linuxNode18, linuxNode14, linuxNode12, linuxNode10]
steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# Ensure to have complete history of commits pushed with given push operation
# It's loose and imperfect assumption that no more than 30 commits will be pushed at once
fetch-depth: 30
# Tag needs to be pushed with real user token, otherwise pushed tag won't trigger the actions workflow
# Hence we're passing 'serverless-ci' user authentication token
token: ${{ secrets.USER_GITHUB_TOKEN }}
- name: Tag if new version
if: github.event.before != '0000000000000000000000000000000000000000' # Skip on first commit
run: |
NEW_VERSION=`git diff -U0 ${{ github.event.before }} package.json | grep '"version": "' | tail -n 1 | grep -oE "[0-9]+\.[0-9]+\.[0-9]+"` || :
if [ -n "$NEW_VERSION" ];
then
git tag v$NEW_VERSION
git push --tags
fi
59 changes: 59 additions & 0 deletions .github/workflows/publish.yml
@@ -0,0 +1,59 @@
# Version tags only

name: Publish

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
env:
# It'll work with secrets.GITHUB_TOKEN (which is provided by GitHub unconditionally)
# Still then release author would be "github-actions"
GITHUB_TOKEN: ${{ secrets.USER_GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Retrieve dependencies from cache
uses: actions/cache@v2
with:
path: |
~/.npm
node_modules
key: npm-v16-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}

- name: Install Node.js and npm
uses: actions/setup-node@v1
with:
node-version: 16.x
registry-url: https://registry.npmjs.org

- name: Build
run: npm run build

- name: Publish new version
# Note: Setting NODE_AUTH_TOKEN as job|workspace wide env var won't work
# as it appears actions/setup-node sets own value
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish

# Normally we have a guarantee that deps are already there, still it may not be the case when:
# - `master` build for same commit failed (and we still pushed tag manually)
# - We've pushed tag manually before `master` build finalized
- name: Install dependencies
if: steps.cacheNpm.outputs.cache-hit != 'true'
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Publish release notes
run: |
TEMP_ARRAY=($(echo $GITHUB_REF | tr "/" "\n"))
TAG=${TEMP_ARRAY[@]: -1}
npx github-release-from-cc-changelog $TAG

0 comments on commit 9bc00cc

Please sign in to comment.