Last active
January 1, 2022 10:47
-
-
Save yakovlev-alexey/75a1d1e519eff586b518624c81fc0930 to your computer and use it in GitHub Desktop.
A GitHub Actions Workflow for linting, testing, automatically versioning and releasing npm packages
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
name: main | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
sanity: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set cache directory | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn --frozen-lockfile | |
- name: Lint | |
run: yarn lint | |
unit: | |
needs: sanity | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set cache directory | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
run: yarn --frozen-lockfile | |
- name: Test | |
run: yarn test | |
release: | |
needs: unit | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Bump version | |
id: bump-version | |
uses: 'yakovlev-alexey/bump-package-version-action@v1.1.0' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
major-wording: 'feat!' | |
minor-wording: 'feat' | |
patch-wording: 'fix' | |
- name: Set cache directory | |
if: steps.bump-version.outputs.version != null | |
id: yarn-cache-dir-path | |
run: echo "::set-output name=dir::$(yarn cache dir)" | |
- uses: actions/cache@v2 | |
if: steps.bump-version.outputs.version != null | |
id: yarn-cache | |
with: | |
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | |
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-yarn- | |
- name: Install dependencies | |
if: steps.bump-version.outputs.version != null | |
run: yarn --frozen-lockfile | |
- name: Publish npm | |
if: steps.bump-version.outputs.version != null | |
env: | |
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
run: yarn publish --non-interactive --registry https://registry.npmjs.org/ | |
- name: Tag latest | |
if: steps.bump-version.outputs.version != null && github.event_name != 'pull_request' | |
env: | |
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
run: yarn tag add --non-interactive <package_name>@${{ steps.bump-version.outputs.version }} latest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment