Build Node.js package #217
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic workflow to help you get started with Actions | |
name: Build Node.js package | |
# Controls when the action will run. Triggers the workflow on push | |
# events but only for the master branch | |
on: | |
push: | |
branches: [ master ] | |
schedule: | |
- cron: '0 0 * * 0,4' | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
env: | |
DATA_FOLDER_NAME: "data" | |
ISOBUSPARAMETER_URL: "https://www.isobus.net/isobus/attachments/isoExport_csv.zip" | |
ISOBUSPARAMETER_FILENAME: "isoExport_csv.zip" | |
ISOBUSPARAMETER_TARGET_FOLDER: "isoExport" | |
EVENT: ${{ github.event_name }} | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Setup environment | |
uses: actions/setup-node@v1 | |
with: | |
node-version: '12.x' | |
registry-url: 'https://registry.npmjs.org/' | |
- name: Setup git config | |
run: | | |
git config --local user.name 'Github Actions' | |
git config --local user.email '[email protected]' | |
- name: Download isobus parameters | |
run: bash ./scripts/download_data.sh | |
- name: Cache last isobus parameter file from cache | |
env: | |
ISOBUSPARAMETER_FILENAME_FULL: "${{env.DATA_FOLDER_NAME}}/${{env.ISOBUSPARAMETER_FILENAME}}" | |
id: cache-parameters | |
uses: actions/cache@v2 | |
with: | |
path: ${{ env.ISOBUSPARAMETER_FILENAME_FULL }} | |
key: last-isobus-parameters-${{ hashFiles(env.ISOBUSPARAMETER_FILENAME_FULL) }} | |
- name: Install npm dependencies | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: npm ci | |
- name: Increase version number (on automated build) | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' && github.event_name == 'schedule' }} | |
run: npm version patch -m "Upgrade to %s for automated build" | |
- name: Increase version number (on push) | |
if: ${{ github.event_name == 'push' }} | |
run: npm version minor -m "Upgrade to %s for manual change" | |
- name: Rebuild node package | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: npm run build | |
- name: Show dist content | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: ls -lahR dist/ | |
- name: Pack a .tar archive | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: | | |
mkdir -p artifacts/ | |
cd artifacts/ | |
npm pack ../ | |
- name: Upload .tar archive as artifact | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: npm-package-artifact | |
path: artifacts/ | |
- name: Publish npm package to registry | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | |
- name: Clean workspace | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
run: git reset --hard | |
- name: Push changes | |
if: ${{ steps.cache-parameters.outputs.cache-hit != 'true' || github.event_name == 'push' }} | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |