Skip to content

Merge pull request #56 from SuperITMan/bugfix/fix-ci-release-publish #76

Merge pull request #56 from SuperITMan/bugfix/fix-ci-release-publish

Merge pull request #56 from SuperITMan/bugfix/fix-ci-release-publish #76

Workflow file for this run

name: ci
on:
push:
branches:
- master
- 1.[0-9]+.x
tags:
- "*"
pull_request:
branches:
- master
- 1.[0-9]+.x
env:
TZ: "Europe/Brussels"
MAIN_NODEJS: "20"
NPM_VERSION: "10.x"
LOGS_DIR: /tmp/ngx-form-errors/logs
LOGS_FILE: /tmp/ngx-form-errors/logs/build-perf.log
HUSKY: 0
jobs:
build-test:
name: Build and Test on node ${{ matrix.node_version }} and ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: ["20"]
os: [ubuntu-latest]
experimental: [false]
# Mark following configurations as "experimental" and allow to continue in case of error
# See documentation: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#example-including-new-combinations
include:
- os: macos-latest
node_version: 20
experimental: true
steps:
# Some actions should be executed only in one environment.
# This variable determines if it is the main environment, it means the same than the one we have internally.
- name: Set environment variable 'IS_MAIN_ENVIRONMENT'
run: |
if [[ '${{ matrix.node_version }}' == '${{ env.MAIN_NODEJS }}' ]] && [[ '${{ matrix.os }}' == 'ubuntu-latest' ]]; then
echo "IS_MAIN_ENVIRONMENT=1" >> $GITHUB_ENV
else
echo "IS_MAIN_ENVIRONMENT=0" >> $GITHUB_ENV
fi
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
# See: https://github.com/marketplace/actions/cache
# See doc: https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows
- name: Cache node modules
uses: actions/cache@v4
env:
cache-name: cache-node-modules-${{ matrix.node_version }}-${{ matrix.os }}
with:
# npm cache files are stored in `~/.npm` on Linux
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
- name: List main variables
run: |
echo "Commit SHA : ${GITHUB_SHA}"
echo "Reference : ${GITHUB_REF}"
echo "Head branch : ${GITHUB_HEAD_REF}"
echo "Base branch : ${GITHUB_BASE_REF}"
echo "Build number: ${GITHUB_RUN_NUMBER}"
echo "Repository : ${GITHUB_REPOSITORY}"
echo "Event : ${GITHUB_EVENT_NAME}"
echo "Author : ${GITHUB_ACTOR}"
echo "Main ENV : ${{ env.IS_MAIN_ENVIRONMENT }}"
NODE_VERSION="$(node -v)"
echo "Node version: $NODE_VERSION"
# This ensures that we are authenticated without requiring to have an actual .npmrc file within the project
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Install dependencies
run: |
npm ci
npm run install:ci:demo:ng-previous
npm run install:ci:demo:ng-latest
- name: Linting and testing
run: |
npm run lint:all
npm run test:ci:all
- name: Generate docs coverage
run: npm run docs:coverage
if: env.IS_MAIN_ENVIRONMENT == 1
# See: https://github.com/marketplace/actions/upload-a-build-artifact
- name: Upload ngx-form-errors dist folder
uses: actions/upload-artifact@v4
with:
name: ngx-form-errors-dist
path: dist
if: env.IS_MAIN_ENVIRONMENT == 1
# See: https://github.com/marketplace/actions/coveralls-github-action
- name: Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: "reports/coverage/lcov.info"
if: env.IS_MAIN_ENVIRONMENT == 1
release:
name: Release
runs-on: "ubuntu-latest"
needs: build-test
if: startsWith(github.ref, 'refs/tags/')
steps:
# See: https://github.com/marketplace/actions/checkout
- uses: actions/checkout@v4
# See: https://github.com/marketplace/actions/setup-node-js-environment
- name: Use Node.js ${{ env.MAIN_NODEJS }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.MAIN_NODEJS }}
- name: Install npm ${{ env.NPM_VERSION }}
run: npm i -g npm@${{ env.NPM_VERSION }}
# See: https://github.com/marketplace/actions/download-a-build-artifact
- uses: actions/download-artifact@v4
with:
name: ngx-form-errors-dist
path: dist
- name: Create file & folder for GitHub Actions logs
run: |
# cfr scripts/_ghactions-group.sh
mkdir -p $LOGS_DIR
touch $LOGS_FILE
- name: Release
run: npm run release:publish
- name: Save logs
run: bash ./scripts/ci/print-logs.sh