Skip to content

Commit

Permalink
ci(github): revise github actions ci workflows
Browse files Browse the repository at this point in the history
- [x] clean up workflows, add comments to justify suggestions;
- [x] implement a reusable workflow that might be used later, add explanatory comments;
  • Loading branch information
rfprod committed Jun 8, 2022
1 parent a43cf73 commit 838c621
Show file tree
Hide file tree
Showing 5 changed files with 314 additions and 162 deletions.
147 changes: 0 additions & 147 deletions .github/workflows/build- tagged.yml

This file was deleted.

37 changes: 37 additions & 0 deletions .github/workflows/get-variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# For more information see:
# - https://docs.github.com/en/actions/using-workflows/reusing-workflows
# - https://docs.github.com/en/actions/using-workflows/reusing-workflows#limitations

# Note:
# This workflow might be used after code is merged into the master branch.
# The workflow is references in other workflows like: ngxs/store/.github/workflows/get-variables.yml@master

name: get-variables

on:
workflow_call:
outputs:
shortref:
description: "Branch name"
value: ${{ jobs.get-variables.outputs.shortref }}
commitsha:
description: "GitHub commit SHA"
value: ${{ jobs.get-variables.outputs.commitsha }}
yarncachedir:
description: "Yarn cache directory"
value: ${{ jobs.get-variables.outputs.yarncachedir }}

jobs:
get-variables:
name: Get variables (branch name, commit hash, yarn cache directory)
runs-on: ubuntu-latest
outputs:
shortref: ${{ steps.get-variables.outputs.firstword }}
commitsha: ${{ steps.get-variables.outputs.secondword }}
yarncachedir: ${{ steps.get-variables.outputs.secondword }}
steps:
- id: get-variables
run: |
echo "::set-output name=shortref::${GITHUB_REF#refs/*/}";
echo "::set-output name=commitsha::$(echo ${GITHUB_SHA})";
echo "::set-output name=yarncachedir::$(yarn cache dir)";
38 changes: 29 additions & 9 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ concurrency:
cancel-in-progress: true

jobs:
## the reusable job will work after the PR is merged and files are committed to the master branch
# get-variables:
# uses: ngxs/store/.github/workflows/get-variables.yml@master # <- references a reusable workflow file and a branch

premerge:
runs-on: ubuntu-latest
# needs: get-variables # this can be uncommented after the reusable job works (see above)

strategy:
matrix:
Expand All @@ -42,7 +47,8 @@ jobs:
- name: Configure kernel (increase watchers)
run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

- name: Get variables (branch name, commit hash, yarn cache directory,)
# this step might be replaced with a reusable workflow get-variables.yml (see above)
- name: Get variables (branch name, commit hash, yarn cache directory)
id: get-variables
run: |
echo "::set-output name=shortref::${GITHUB_REF#refs/*/}";
Expand All @@ -64,10 +70,18 @@ jobs:
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}-branch-
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
${{ runner.os }}-
## the above might be replaced with the commented code beneath if a reusable workflow get-variables.yml is used (see above)
# key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}-branch-${{ needs.get-variables.outputs.shortref }}-workspace-${{ needs.get-variables.outputs.commitsha }}
# restore-keys: |
# ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}-branch-${{ needs.get-variables.outputs.shortref }}-workspace-
# ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}-branch-
# ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
# ${{ runner.os }}-

- name: Install project dependencies
run: yarn install --frozen-lockfile --non-interactive

# Is 'yarn pack --filename ./dist/ngxs-core.tgz' needed during premerge checks?
- name: Compile NGXS and create a pack
run: |
yarn build
Expand All @@ -82,12 +96,15 @@ jobs:
- name: Unit Tests
run: yarn test:ci

## This step was commented in the CircleCI workflows config.
# - name: Integration Tests
# run: yarn test:ci:integration

## This step was commented in the CircleCI workflows config.
# - name: E2E Tests
# run: yarn test:ci:e2e

## This step was commented in the CircleCI workflows config.
# - name: Integration Tests - SSR
# run: yarn test:ci:integration:ssr

Expand Down Expand Up @@ -127,11 +144,14 @@ jobs:
- name: Check the size of NGXS bundle
run: yarn bundlesize

- name: Upload coverage results to Code Climate
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/cc-test-reporter
chmod +x /tmp/cc-test-reporter
/tmp/cc-test-reporter after-build --coverage-input-type lcov --exit-code 0
env:
CC_TEST_REPORTER_ID: 3f4c9a9d57ded045e0f9ab5d23e5bbcbf709bb85637bea555f1233e72134b818 # TODO: better store it in secrets. Name the variable: CC_TEST_REPORTER_ID. Then delete this line and uncomment the nest one
# CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
## Actually, this is probably not needed during premerge checks.
## It makes sense to store test results only after testing already code merged into the trunk.
## It does not seem to make sense to upload test results after each push to the branch that has not need merged into the trunk, there will be a lot of useless artifacts on Code Climate.
# - name: Upload coverage results to Code Climate
# run: |
# curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > /tmp/cc-test-reporter
# chmod +x /tmp/cc-test-reporter
# /tmp/cc-test-reporter after-build --coverage-input-type lcov --exit-code 0
# env:
# CC_TEST_REPORTER_ID: 3f4c9a9d57ded045e0f9ab5d23e5bbcbf709bb85637bea555f1233e72134b818 # TODO: better store it in the repository secrets. Name the variable: CC_TEST_REPORTER_ID. Then delete this line and uncomment the next one
# # CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
Loading

0 comments on commit 838c621

Please sign in to comment.