Skip to content

Commit

Permalink
CI: Enable Trunk Check (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er authored Jan 14, 2025
1 parent a778bf9 commit b1b1a2e
Show file tree
Hide file tree
Showing 42 changed files with 346 additions and 115 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ assignees: ''

---

<!-- markdownlint-disable -->
**Describe the bug**
A clear and concise description of what the bug is.

Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Enhancement Request
about: Suggest an enhancement to the Lens application
labels: enhancement
---
<!-- markdownlint-disable -->
<!-- Please only use this template for submitting enhancement requests -->
<!--
Check already existing enhancement request on this list: https://github.com/freelensapp/freelens/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- markdownlint-disable -->
Fixes #

**Description of changes:**
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/kubectl-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
types:
- created
schedule:
- cron: "26 6 * * *"
- cron: 26 6 * * *
workflow_dispatch: {}

permissions:
Expand Down Expand Up @@ -91,6 +91,7 @@ jobs:
push: origin automated/kubectl-versions --set-upstream --force

- name: Create pull request
id: pr
if: env.changes == 'true'
uses: devops-infra/action-pull-request@master
with:
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/trunk-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Trunk Check

on:
push:
branches:
- "**"
pull_request:
branches:
- main
workflow_dispatch: {}

permissions:
contents: read

jobs:
trunk:
name: Trunk Check

runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Trunk Check
uses: trunk-io/trunk-action@v1
with:
check-mode: all
116 changes: 116 additions & 0 deletions .github/workflows/trunk-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Automated trunk upgrade

on:
issue_comment:
types:
- created
push:
branches:
- main
paths:
- .trunk/**
schedule:
- cron: 2 6 * * *
workflow_dispatch: {}

permissions:
contents: write
pull-requests: write

jobs:
trunk-upgrade:
name: trunk upgrade

runs-on: ubuntu-20.04
environment: automated

if: >-
github.event_name != 'issue_comment' ||
contains(github.event.comment.body, '/rerun')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}

- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Get npm cache directory
run: echo "npm_cache_dir=$(npm config get cache)" >> ${GITHUB_ENV}

- name: Use cache
uses: actions/cache@v4
with:
path: ${{ env.npm_cache_dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies for plugin
uses: nick-fields/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
retry_on: error
command: npm ci

- name: Set up Trunk
run: curl https://get.trunk.io -fsSL | bash -s -- -y

- name: Trunk upgrade
run: |
trunk upgrade --yes-to-all --no-progress --ci --color | tee .github/update.log
sed -e '/Downloading Trunk/,/Unpacking Trunk... done/d' -e 's/\x1b\[[0-9;]*m//g' -e 's/^\( \)\{0,1\} /\1- /' .github/update.log > .github/pr_body.log
- name: Check for changes
run: |
if git diff --exit-code; then
echo "changes=false" >> $GITHUB_ENV
else
echo "changes=true" >> $GITHUB_ENV
fi
- name: Trunk Check
if: env.changes == 'true'
uses: trunk-io/trunk-action@v1
with:
check-mode: all
continue-on-error: true

- name: Commit and push to branch
if: env.changes == 'true'
uses: EndBug/add-and-commit@v9
with:
github_token: ${{ secrets.GH_TOKEN }}
default_author: github_actions
message: Automated trunk upgrade
new_branch: automated/trunk-upgrade
fetch: false
push: origin automated/trunk-upgrade --set-upstream --force

- name: Create pull request
id: pr
if: env.changes == 'true'
uses: devops-infra/action-pull-request@master
with:
github_token: ${{ secrets.GH_TOKEN }}
target_branch: main
label: automated
title: Automated trunk upgrade
get_diff: false

- name: Update pull request description
if: env.changes == 'true'
run: gh pr edit ${{ steps.pr.outputs.pr_number }} --body-file .github/pr_body.log
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

- name: Close pull request
if: env.changes == 'false'
run: gh pr list --head automated/trunk-upgrade --json number --jq '.[].number' | xargs -rn1 gh pr close --delete-branch
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
4 changes: 4 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Prettier friendly markdownlint config (all formatting rules disabled)
extends: markdownlint/style/prettier
# Emphasis used instead of a header
MD036: false
7 changes: 7 additions & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
14 changes: 14 additions & 0 deletions .trunk/configs/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false, // https://github.com/svg/svgo/issues/1128
sortAttrs: true,
removeOffCanvasPaths: true,
},
},
},
],
};
40 changes: 40 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.8
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.6
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
lint:
enabled:
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
disabled:
- checkov
- osv-scanner
- oxipng
- prettier
- svgo
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
7 changes: 7 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
6 changes: 3 additions & 3 deletions packages/business-features/keyboard-shortcuts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

This Feature enables keyboard shortcuts in Lens

# Usage
## Usage

```bash
$ npm install @freelensapp/keyboard-shortcuts
```sh
npm install @freelensapp/keyboard-shortcuts
```

```typescript
Expand Down
6 changes: 3 additions & 3 deletions packages/infrastructure/eslint-config/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Lens Code Style

**Note:** This package contains Eslint and Prettier configurations, name of package is `@freelensapp/eslint-config` just because Eslint has arbitrary requirement (https://eslint.org/docs/latest/extend/shareable-configs).
**Note:** This package contains Eslint and Prettier configurations, name of package is `@freelensapp/eslint-config` just because Eslint has arbitrary requirement (<https://eslint.org/docs/latest/extend/shareable-configs>).

## Usage

1. Install `@freelensapp/eslint-config`
2. Create `.prettierrc` that contains `"@freelensapp/eslint-config/prettier"`
3. Add a `.eslintrc.js` that extends `@freelensapp/eslint-config/eslint`, for example:

```
```js
module.exports = {
extends: "@freelensapp/eslint-config/eslint",
parserOptions: {
Expand All @@ -19,7 +19,7 @@ module.exports = {

4. Add linting and formatting scripts to `package.json`

```
```json
{
"scripts": {
"lint": "lens-lint",
Expand Down
10 changes: 5 additions & 5 deletions packages/infrastructure/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This package contains jest configurations and scripts for Lens packages.

## Install

```
$ npm install @freelensapp/jest
```sh
npm install @freelensapp/jest
```

## Features
Expand All @@ -15,14 +15,14 @@ Shared configurations for minimal duplication.

#### Node

**./packages/<any-package>/jest.config.js**
**./packages/any-package/jest.config.js**
```javascript
module.exports = require("@freelensapp/jest").monorepoPackageConfig(__dirname).configForNode;
```

#### React

**./packages/<any-package>/jest.config.js**
**./packages/any-package/jest.config.js**
```javascript
module.exports = require("@freelensapp/jest").monorepoPackageConfig(__dirname).configForReact;
```
Expand All @@ -41,7 +41,7 @@ module.exports = require("@freelensapp/jest").monorepoRootConfig(__dirname);
#### lens-test
Test package with coverage enforcement. Automatically opens coverage report in case of failure.

**./packages/<any-package>/package.json**
**./packages/any-package/package.json**
```json
{
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions packages/infrastructure/jest/bin/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

jest --coverage --runInBand
result=$?

[ $result != 0 ] && [ -v $CI ] && open ./coverage/lcov-report/index.html
[[ ${result} != 0 ]] && [[ -v ${CI} ]] && open ./coverage/lcov-report/index.html

exit $result
exit "${result}"
4 changes: 2 additions & 2 deletions packages/infrastructure/typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This package contains typescript configurations for Lens packages.

## Install

```
$ npm install @freelensapp/typescript
```sh
npm install @freelensapp/typescript
```

## Features
Expand Down
4 changes: 2 additions & 2 deletions packages/infrastructure/webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This package contains webpack configurations for Lens packages.

## Install

```
$ npm install @freelensapp/webpack
```sh
npm install @freelensapp/webpack
```

## Features
Expand Down
6 changes: 3 additions & 3 deletions packages/logger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

This package contains stuff related to creating Lens-applications.

# Usage
## Usage

```bash
$ npm install @freelensapp/logger
```sh
npm install @freelensapp/logger
```

```typescript
Expand Down
Loading

0 comments on commit b1b1a2e

Please sign in to comment.