From 8cf75cac92d610274fc4acd03f16c28ab27a849e Mon Sep 17 00:00:00 2001 From: Rickard Natt och Dag Date: Wed, 6 Apr 2022 09:21:15 +0200 Subject: [PATCH] feat(github-actions): update workflows 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. --- src/templates/github_actions/js/pr_check.yml | 50 ++++++++-- src/templates/github_actions/js/release.yml | 91 +++++++++++++++---- .../github_actions/rescript/pr_check.yml | 22 +++-- .../github_actions/rescript/release.yml | 51 +++++++---- .../github_actions/rust/pr_check.yml | 38 ++++++++ src/templates/github_actions/rust/release.yml | 13 ++- 6 files changed, 205 insertions(+), 60 deletions(-) create mode 100644 src/templates/github_actions/rust/pr_check.yml diff --git a/src/templates/github_actions/js/pr_check.yml b/src/templates/github_actions/js/pr_check.yml index cb1d4f6..6a50c1c 100644 --- a/src/templates/github_actions/js/pr_check.yml +++ b/src/templates/github_actions/js/pr_check.yml @@ -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 + diff --git a/src/templates/github_actions/js/release.yml b/src/templates/github_actions/js/release.yml index 323b1e9..f78a538 100644 --- a/src/templates/github_actions/js/release.yml +++ b/src/templates/github_actions/js/release.yml @@ -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 }} diff --git a/src/templates/github_actions/rescript/pr_check.yml b/src/templates/github_actions/rescript/pr_check.yml index 0662a7e..eed8ded 100644 --- a/src/templates/github_actions/rescript/pr_check.yml +++ b/src/templates/github_actions/rescript/pr_check.yml @@ -2,7 +2,7 @@ name: Run tests on PR on: pull_request: - branches: + branches: - main jobs: @@ -10,16 +10,18 @@ jobs: 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 + diff --git a/src/templates/github_actions/rescript/release.yml b/src/templates/github_actions/rescript/release.yml index f7311c7..230c73b 100644 --- a/src/templates/github_actions/rescript/release.yml +++ b/src/templates/github_actions/rescript/release.yml @@ -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 }} diff --git a/src/templates/github_actions/rust/pr_check.yml b/src/templates/github_actions/rust/pr_check.yml new file mode 100644 index 0000000..364758d --- /dev/null +++ b/src/templates/github_actions/rust/pr_check.yml @@ -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 + diff --git a/src/templates/github_actions/rust/release.yml b/src/templates/github_actions/rust/release.yml index 30c0715..d7ca987 100644 --- a/src/templates/github_actions/rust/release.yml +++ b/src/templates/github_actions/rust/release.yml @@ -2,9 +2,8 @@ name: Release on: push: - branches: [ main ] - pull_request: - branches: [ main ] + branches: + - main env: CARGO_TERM_COLOR: always @@ -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: @@ -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)