Skip to content

Commit

Permalink
feat(github-actions): update workflows
Browse files Browse the repository at this point in the history
All workflows now support automatic cancelling of previous runs if
a new commit is added. We also added better caching support for npm
based projects and split those workflows into more steps which makes
the workflows run faster.
  • Loading branch information
Rickard Natt och Dag committed Apr 6, 2022
1 parent d677dbd commit 8cf75ca
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 60 deletions.
50 changes: 40 additions & 10 deletions src/templates/github_actions/js/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,54 @@ name: Run tests on PR

on:
pull_request:
branches:
branches:
- main

jobs:
install:
name: Install dependencies
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

lint:
name: Run linting
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests and linting
run: npm run lint --if-present

test:
name: Run tests
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v1
- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests and linting
run: |
npm ci
npm run lint --if-present
npm test
env:
CI: true
run: npm test

91 changes: 74 additions & 17 deletions src/templates/github_actions/js/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,92 @@ on:
- main

jobs:
build:
install:
name: Install dependencies
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

test:
name: Tests
runs-on: ubuntu-latest
needs: [install]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests
run: npm test

lint:
name: Lint
runs-on: ubuntu-latest
needs: [install]
steps:
- name: Cancel Previous Runs
uses: styfl/cancel-workflow-action@0.9.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run linting
run: npm run lint

typecheck:
name: TypeScript
needs: [install]
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v1
- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests and linting
run: |
npm install
npm run lint --if-present
npm test
env:
CI: true
- name: Type check
run: npm run typecheck

- name: Create release using semantic-release
release:
runs-on: ubuntu-latest
needs: [test, lint, typecheck]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Build project
run: npm run build

- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
semantic_version: 17.1.1
extra_plugins: |
@semantic-release/changelog@5.0.1
@semantic-release/git@9.0
env:
# GITHUB_TOKEN is added automatically by GitHub
GITHUB_TOKEN: {{{{raw}}}}${{ secrets.GITHUB_TOKEN }}{{{{/raw}}}}
{{#unless noNpm}}NPM_TOKEN: {{{{raw}}}}${{ secrets.NPM_TOKEN }}{{{{/raw}}}}{{/unless}}

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22 changes: 12 additions & 10 deletions src/templates/github_actions/rescript/pr_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,26 @@ name: Run tests on PR

on:
pull_request:
branches:
branches:
- main

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Setup Node
uses: actions/setup-node@v1
- name: Build project
run: npm run build

- name: Run tests and linting
run: |
npm ci
npm run build
npm test
env:
CI: true
run: npm test

51 changes: 33 additions & 18 deletions src/templates/github_actions/rescript/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,50 @@ on:
- main

jobs:
build:

test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
with:
access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout code
uses: actions/checkout@v3

- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Build application
run: npm run build

- name: Run tests
run: npm test

release:
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v1
- name: Download dependencies
uses: bahmutov/npm-install@v1

- name: Run tests and linting
run: |
npm install
npm run build
npm test
env:
CI: true
- name: Build project
run: npm run build

- name: Create release using semantic-release
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
id: semantic
with:
semantic_version: 17.1.1
extra_plugins: |
@semantic-release/changelog@5.0.1
@semantic-release/git@9.0
env:
# GITHUB_TOKEN is added automatically by GitHub
GITHUB_TOKEN: {{{{raw}}}}${{ secrets.GITHUB_TOKEN }}{{{{/raw}}}}
{{#unless noNpm}}NPM_TOKEN: {{{{raw}}}}${{ secrets.NPM_TOKEN }}{{{{/raw}}}}{{/unless}}

GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
38 changes: 38 additions & 0 deletions src/templates/github_actions/rust/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release

on:
pull_request:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1

- name: Checkout code
uses: actions/checkout@v3

- name: Setup Rust (nightly)
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
components: rustfmt, clippy
override: true

- name: Run linting
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Run formatting
run: cargo fmt --all -- --check

- name: Run tests
run: cargo test --locked

13 changes: 8 additions & 5 deletions src/templates/github_actions/rust/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Release

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
branches:
- main

env:
CARGO_TERM_COLOR: always
Expand All @@ -18,8 +17,10 @@ jobs:
release: {{{{raw}}}}${{ steps.semantic.outputs.new_release_version }}{{{{/raw}}}}
new_release_published: {{{{raw}}}}${{ steps.semantic.outputs.new_release_published }}{{{{/raw}}}}
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Rust (nightly)
uses: actions-rs/toolchain@v1
with:
Expand Down Expand Up @@ -70,8 +71,10 @@ jobs:
NAME: {{name}}-{{{{raw}}}}${{ needs.test.outputs.release }}-x86_64-apple-darwin{{{{/raw}}}}
TARGET: x86_64-apple-darwin
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.9.1
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: 'main'
- name: Setup Rust (nightly)
Expand Down

0 comments on commit 8cf75ca

Please sign in to comment.