simple-icons/.github/workflows/publish.yml
Eric Cornelissen a95ad430a3
Improve CI config: caching & refactoring (#5912)
* Set up caching jest cache for tests in CI

Use actions/cache to cache the jest cache between runs. The cache will
be invalided if the package-lock.json file is updated OR after 7
days [1]. The cache directory for jest is now also configured to be in a
directory called ".jestcache" at the root of this project. This
directory will be ignored by git due to its addition to the .gitignore.

--
1. https://docs.github.com/en/actions/guides/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy

* Trigger jest cache in CI

* Include date in cache key

This way the cache is invalidated very day

* Add name for caching Jest's cache step

* Demonstrate test failure with cache enabled

* Revert ff915d466075d5292c7b5772406ff62fe1a3e220

* Cache dependencies

* Update Jest cache configuration

* Refactor and use Jest cache in Publish workfow

- Refactor out the duplicated sanity check in the publish workflow into
  a separate, depended upon, job.
- Use the Jest cache in the Publish workflow.

* Update linter job in CI to just run `npm run lint`

... whereas previously it ran each linter separately. This avoids having
to update the workflow file if a new linter is added (or a linter is
removed).

* Use run_number instead of date for jest cache in CI

* Simplify GitHub release publish job
2021-06-29 12:07:50 +02:00

122 lines
4.0 KiB
YAML

name: Publish Releases
on:
push:
branches:
- master
jobs:
sanity-check:
name: Pre-publish checks
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v2
with:
node-version: 12.x
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache Jest
uses: actions/cache@v2
with:
path: .cache/jest
key: ${{ runner.os }}-jest-${{ hashFiles('package-lock.json') }}-${{ github.run_number }}
restore-keys: |
${{ runner.os }}-jest-${{ hashFiles('package-lock.json') }}-
${{ runner.os }}-jest-
- name: Install dependencies
run: npm ci
- name: Build NodeJS package
run: npm run build
- name: Run linters
run: npm run lint
- name: Run tests
run: npm run test
npm:
name: NPM Package
needs: sanity-check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v2
with:
node-version: 12.x
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Deploy to NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
github:
name: GitHub release
needs: sanity-check
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Get commit message (for release title and body)
id: commit
uses: kceb/git-message-action@v1
- name: Get release title and body
id: release
run: |
RELEASE_TITLE=$(echo "${{ steps.commit.outputs.git-message }}" | head -n 1)
echo "::set-output name=title::$RELEASE_TITLE"
RELEASE_BODY=$(echo "${{ steps.commit.outputs.git-message }}" | tail -n $(expr $(echo "${{ steps.commit.outputs.git-message }}" | wc -l) - 1))
echo "::set-output name=body::$RELEASE_BODY"
- name: Get release version
id: get-version
run: |
export PACKAGE_VERSION=$(cat package.json | grep 'version' | sed 's/[ \",:]//g' | sed 's/version//')
echo "::set-output name=version::$PACKAGE_VERSION"
- name: Create and push git tag
uses: actions-ecosystem/action-push-tag@v1
with:
tag: ${{ steps.get-version.outputs.version }}
message: ${{ steps.commit.outputs.git-message }}
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get-version.outputs.version }}
release_name: ${{ steps.release.outputs.title }}
body: ${{ steps.release.outputs.body }}
font:
name: Trigger simple-icons-font release
needs: npm
runs-on: ubuntu-latest
steps:
- name: Trigger simple-icons-font release
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REMOTE_DISPATCH_TOKEN }}" \
-d '{"ref":"develop"}' \
https://api.github.com/repos/simple-icons/simple-icons-font/actions/workflows/auto-release.yml/dispatches
website:
name: Trigger simple-icons-website update
needs: npm
runs-on: ubuntu-latest
steps:
- name: Trigger simple-icons-website update
run: |
curl -X POST \
-H "Authorization: Bearer ${{ secrets.REMOTE_DISPATCH_TOKEN }}" \
-d '{"ref":"master"}' \
https://api.github.com/repos/simple-icons/simple-icons-website/actions/workflows/auto-release.yml/dispatches