From b736429a195c94d7c9512b5ec2c25378b2b2b8ae Mon Sep 17 00:00:00 2001 From: Tsuyoshi HARA Date: Thu, 12 Dec 2024 14:22:24 +0900 Subject: [PATCH 1/4] feat: Add reusable workflow to run eslint --- .github/workflows/reusable-lint.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/reusable-lint.yml diff --git a/.github/workflows/reusable-lint.yml b/.github/workflows/reusable-lint.yml new file mode 100644 index 00000000..73a91966 --- /dev/null +++ b/.github/workflows/reusable-lint.yml @@ -0,0 +1,26 @@ +name: Reusable workflow example + +on: + workflow_call: + # inputs: + # config-path: + # required: true + # type: string + # secrets: + # token: + # required: true + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version-file: ".node-version" + cache: "yarn" + - name: Run ESLint + run: | + BASE_BRANCH=${GITHUB_BASE_REF:-master} + BASE_COMMIT=$(git merge-base HEAD origin/${BASE_BRANCH}) + yarn lint-staged --concurrent=false --diff="${BASE_COMMIT}..HEAD" --verbose From ac7bbeab758cc7bd7b0f4418bc3adba77c526d1c Mon Sep 17 00:00:00 2001 From: Tsuyoshi HARA Date: Thu, 12 Dec 2024 14:31:29 +0900 Subject: [PATCH 2/4] ci: Fix reusable workflow --- .github/workflows/reusable-lint.yml | 40 ++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/workflows/reusable-lint.yml b/.github/workflows/reusable-lint.yml index 73a91966..e1858bb4 100644 --- a/.github/workflows/reusable-lint.yml +++ b/.github/workflows/reusable-lint.yml @@ -2,23 +2,45 @@ name: Reusable workflow example on: workflow_call: - # inputs: - # config-path: - # required: true - # type: string - # secrets: - # token: - # required: true + secrets: + NPM_TOKEN: + required: true jobs: lint: runs-on: ubuntu-latest + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} steps: - - uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + + - name: Use Node.js + uses: actions/setup-node@v4.0.0 with: node-version-file: ".node-version" cache: "yarn" + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - name: Restore cache for yarn and lerna + uses: actions/cache@v3.3.2 + id: yarn-cache + with: + path: | + ${{ steps.yarn-cache-dir-path.outputs.dir }} + node_modules + */*/node_modules + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install dependencies + run: yarn install --frozen-lockfile + - name: Run ESLint run: | BASE_BRANCH=${GITHUB_BASE_REF:-master} From e1a4f486feb7ec17ef362bbe23519df8c9062451 Mon Sep 17 00:00:00 2001 From: Tsuyoshi HARA Date: Thu, 12 Dec 2024 14:38:07 +0900 Subject: [PATCH 3/4] ci: Fix caching --- .github/workflows/reusable-lint.yml | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/.github/workflows/reusable-lint.yml b/.github/workflows/reusable-lint.yml index e1858bb4..2ae54c6f 100644 --- a/.github/workflows/reusable-lint.yml +++ b/.github/workflows/reusable-lint.yml @@ -22,21 +22,11 @@ jobs: node-version-file: ".node-version" cache: "yarn" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT - - - name: Restore cache for yarn and lerna - uses: actions/cache@v3.3.2 - id: yarn-cache + - name: cache node_modules + uses: actions/cache@v4 with: - path: | - ${{ steps.yarn-cache-dir-path.outputs.dir }} - node_modules - */*/node_modules + path: node_modules key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - name: Install dependencies run: yarn install --frozen-lockfile From 3f0de15b744f6f3fdf155a88dd69e51f97f32392 Mon Sep 17 00:00:00 2001 From: Tsuyoshi HARA Date: Thu, 12 Dec 2024 14:50:54 +0900 Subject: [PATCH 4/4] ci: Add input --- .github/workflows/reusable-lint.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-lint.yml b/.github/workflows/reusable-lint.yml index 2ae54c6f..dc145416 100644 --- a/.github/workflows/reusable-lint.yml +++ b/.github/workflows/reusable-lint.yml @@ -2,6 +2,10 @@ name: Reusable workflow example on: workflow_call: + inputs: + default-base-branch: + required: true + type: string secrets: NPM_TOKEN: required: true @@ -33,6 +37,6 @@ jobs: - name: Run ESLint run: | - BASE_BRANCH=${GITHUB_BASE_REF:-master} + BASE_BRANCH=${GITHUB_BASE_REF:-${{ inputs.default-base-branch }}} BASE_COMMIT=$(git merge-base HEAD origin/${BASE_BRANCH}) yarn lint-staged --concurrent=false --diff="${BASE_COMMIT}..HEAD" --verbose