name: CI - Main on: push: branches: [ 'master' ] tags: [ 'v*' ] jobs: start: # This prevents a tag running twice as it'll have a "tag" and a "commit" event # We only want the tag to run the action as it'll be able to create the release notes if: (startsWith(github.event.ref, 'refs/heads/') && !startsWith(github.event.head_commit.message, 'chore(release)')) || (startsWith(github.event.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: Install libvirt-dev run: sudo apt-get install libvirt-dev - 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: Install libvirt-dev run: sudo apt-get install libvirt-dev - name: Installing node deps run: npm install - name: Check coverage run: npm run cover:types compile-source: 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.15.3 - 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: Install libvirt-dev run: sudo apt-get install libvirt-dev - 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: [compile-source] 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.15.3 - 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: 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 > ${{ github.workspace }}/RELEASE_NOTES.md && \ # Log release notes cat ${{ github.workspace }}/RELEASE_NOTES.md - name: Create Github release uses: softprops/action-gh-release@v1 with: body_path: ${{ github.workspace }}/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 # We get the second to last tag as the last is the current one LAST_RELEASE=$(git tag --list --sort=v:refname | grep -v 'alpha\|beta\|rc' | tail -2 | head -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 | sed \$d) \ # Save release notes to a file echo $RELEASE_NOTES > ${{ github.workspace }}/RELEASE_NOTES.md && \ # Log release notes cat ${{ github.workspace }}/RELEASE_NOTES.md - name: Create Github release uses: softprops/action-gh-release@v1 with: body_path: ${{ github.workspace }}/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 }}