Files
api/.github/workflows/main.yml
2021-03-28 18:49:16 -07:00

302 lines
7.9 KiB
YAML

name: CI - Main
on:
push:
branches:
- $default-branch
tags:
- 'v*'
jobs:
start:
if: |
# This prevents a tag running twice as it'll have a "tag" and a "commit" event
# Normal commit
(github.event.base_ref === "refs/heads/$default-branch" && !startsWith(github.event.head_commit.message, 'chore(release)')) ||
# Release tag
(startsWith(github.event.base_ref, 'refs/tags/') && startsWith(github.event.head_commit.message, 'chore(release)'))
runs-on: ubuntu-latest
steps:
- name: Validate branch and tag
run: exit 0
lint:
runs-on: ubuntu-latest
needs: [start]
steps:
- name: Checkout repo
uses: actions/checkout@v1
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Install node v14
uses: actions/setup-node@v1
with:
node-version: 14
- name: Load npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Installing node deps
run: npm install
- name: Lint
run: npm run lint
coverage:
runs-on: ubuntu-latest
needs: [start]
steps:
- name: Checkout repo
uses: actions/checkout@v1
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Install node v14
uses: actions/setup-node@v1
with:
node-version: 14
- name: Load npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Installing node deps
run: npm install
- name: Check coverage
run: npm run cover:types
build:
runs-on: ubuntu-latest
needs: [lint,coverage]
steps:
- name: Checkout repo
uses: actions/checkout@v1
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Install node v14
uses: actions/setup-node@v1
with:
node-version: 14
- name: Load npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Installing node deps
run: npm install
# See https://github.com/apollographql/subscriptions-transport-ws/issues/433
- name: Patch subscriptions-transport-ws
run: npm run patch:subscriptions-transport-ws
- name: Compile to javascript
run: npm run build
- name: Clean node_modules
run: npm run clean && curl -sf https://gobinaries.com/tj/node-prune | sh && node-prune
- name: Pack source
run: npm pack
- name: Upload source tgz to Github artifacts
uses: actions/upload-artifact@v2
with:
name: unraid-api-source
path: ${{ github.workspace }}/*.tgz
build-binary:
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Install node v14
uses: actions/setup-node@v1
with:
node-version: 14
- name: Load npm cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Download unraid-api source tgz
uses: actions/download-artifact@v2
with:
name: unraid-api-source
- name: Unpack unraid-api source tgz
shell: bash
run: tar xvzf ./unraid-api-*.tgz --strip 1 && rm ./unraid-api-*.tgz
- name: Load nexe cache
uses: actions/cache@v2
with:
path: ~/.nexe
key: ${{ runner.os }}-nexe
restore-keys: |
${{ runner.os }}-nexe
- name: Install nexe
run: npm i -g nexe
- name: Build binary
run: npm run build-binary
- name: Pack binary
run: npm pack
- name: Upload binary tgz to Github artifacts
uses: actions/upload-artifact@v2
with:
name: unraid-api
path: ${{ github.workspace }}/*.tgz
pre-release:
# Only release if this is a alpha|beta|rc tag
if: |
startsWith(github.ref, 'refs/tags/v') &&
(contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc'))
runs-on: ubuntu-latest
needs: [build-binary]
steps:
- name: Checkout repo
uses: actions/checkout@v1
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Download unraid-api binary tgz
uses: actions/download-artifact@v2
with:
name: unraid-api
- name: Create release notes
run: |
# Get the last release tag
LAST_RELEASE=$(git tag --list --sort=v:refname | tail -1); \
# Get all the commit messages between now and the last tag
RELEASE_NOTES=$(git log "$LAST_RELEASE...HEAD" --pretty=format:"- %s [\`%h\`](http://github.com/$GITHUB_REPOSITORY/commit/%H)" --reverse) \
# Save release notes to a file
echo $RELEASE_NOTES > RELEASE_NOTES.md
- name: Create Github release
uses: softprops/action-gh-release@v1
with:
body_path: RELEASE_NOTES.md
draft: false
prerelease: true
files: unraid-api-*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: prerelease
release:
# Only release if this is a version tag
if: |
startsWith(github.ref, 'refs/tags/v') &&
(!contains(github.ref, 'alpha') && !contains(github.ref, 'beta') && !contains(github.ref, 'rc'))
runs-on: ubuntu-latest
needs: [build-binary]
steps:
- name: Checkout repo
uses: actions/checkout@v1
- name: Add SSH deploy key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.UNRAID_BOT_SSH_KEY }}
known_hosts: ${{ secrets.KNOWN_HOSTS }}
- name: Download unraid-api binary tgz
uses: actions/download-artifact@v2
with:
name: unraid-api
- name: Create release notes
run: |
# Get the last release tag
LAST_RELEASE=$(git tag --list --sort=v:refname | grep -v 'alpha\|beta\|rc' | tail -1); \
# Get all the commit messages between now and the last non-pre-release tag
RELEASE_NOTES=$(git log "$LAST_RELEASE...HEAD" --pretty=format:"- %s [\`%h\`](http://github.com/$GITHUB_REPOSITORY/commit/%H)" --reverse) \
# Save release notes to a file
echo $RELEASE_NOTES > RELEASE_NOTES.md
- name: Create Github release
uses: softprops/action-gh-release@v1
with:
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
files: unraid-api-*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: production
version: ${{ github.ref }}