Skip to content

Commit b5b28b5

Browse files
authored
fix(lint-pr-title): adapt action and Dockerfile to bun workspaces (#1120)
* fix(lint-pr-title): adapt action and Dockerfile to bun workspaces The lint-pr-title action was failing to run correctly after the migration to bun workspaces in 9ffb9ce. This was due to two issues: 1. The composite action was not checking out the shared-workflows repository, so the workspace dependencies could not be installed. 2. The Dockerfile was not adapted to the workspace structure, and the tests were failing due to file permission issues. This commit addresses both issues. The action.yml now checks out the shared-workflows repository, following the pattern of other actions in this repository. The Dockerfile is updated to correctly build in a workspace context and to run the tests as a non-root user to ensure file permission tests pass. It sort of kept working because we forgot to remove the bun.lock file in `actions/lint-pr-title.` This papered over the problem until a Bun update needed to update the lock file and it stopped working. Here we remove that. Now that we use files outside of the action's own directory (`package.json`, `bun.lock`), we need to check the repository out and run from the root. * refactor(lint-pr-title): modernise Dockerfile (#1121) The previous Dockerfile was overly complex and inefficient, a result of adapting an older style to a workspace environment. The multi-stage build was difficult to read and did not use modern Docker features for caching. To fix these problems, we simplify the build process into a more readable multi-stage build. We introduce Docker cache mounts for dependency installation, which will result in significantly faster builds. The COPY commands are now more specific to avoid copying unnecessary files into the image. Tests continue to be run as a non-root user to ensure file permission tests work correctly, but in a more streamlined way.
1 parent bece5bb commit b5b28b5

File tree

3 files changed

+58
-594
lines changed

3 files changed

+58
-594
lines changed

actions/lint-pr-title/Dockerfile

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
1+
# This file must be built from the root of the repository.
2+
# Example: docker build . -f actions/lint-pr-title/Dockerfile
3+
14
FROM oven/bun:1.2.18@sha256:2cdd9c93006af1b433c214016d72a3c60d7aa2c75691cb44dfd5250aa379986b AS base
5+
26
WORKDIR /usr/src/app
37

4-
FROM base AS install
5-
RUN mkdir -p /temp/dev
6-
COPY package.json bun.lockb /temp/dev/
7-
RUN cd /temp/dev && bun install --frozen-lockfile
8+
# Create a non-root user to run the tests. Run tests as non-root user because
9+
# one test expects EACCES when writing to a read-only file, and this will not
10+
# fail as root.
11+
RUN useradd -ms /bin/bash newuser
12+
13+
# Install dependencies
14+
FROM base AS deps
15+
16+
COPY package.json bun.lock ./
17+
COPY actions/dependabot-auto-triage/package.json ./actions/dependabot-auto-triage/
18+
19+
# Because we use bun's workspaces, we need to have all package.json files
20+
# available, even if they're not used. (We filter to one workspace.)
21+
COPY actions/get-latest-workflow-artifact/package.json ./actions/get-latest-workflow-artifact/
22+
COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/
23+
24+
RUN --mount=type=cache,target=/root/.bun/install/cache \
25+
bun install --frozen-lockfile --filter lint-pr-title
826

9-
# install with --production (exclude devDependencies)
10-
RUN mkdir -p /temp/prod
11-
COPY package.json bun.lockb /temp/prod/
12-
RUN cd /temp/prod && bun install --frozen-lockfile --production
27+
# Run tests
28+
FROM base AS test
1329

14-
FROM base AS prerelease
15-
COPY --from=install /temp/dev/node_modules node_modules
16-
COPY . .
30+
COPY --from=deps /usr/src/app/node_modules ./node_modules
31+
COPY --chown=newuser:newuser actions/lint-pr-title/ ./actions/lint-pr-title/
32+
USER newuser
1733

18-
# Install dev dependencies to run the tests
1934
ENV NODE_ENV=development
20-
RUN bun install --frozen-lockfile --dev
21-
RUN bun run test
22-
RUN bun run build
2335

24-
FROM base AS release
25-
COPY --from=install /temp/prod/node_modules node_modules
26-
COPY --from=prerelease /usr/src/app/index.ts .
27-
COPY --from=prerelease /usr/src/app/package.json .
36+
RUN bun run --filter lint-pr-title test
37+
38+
# Assemble final image from a clean stage
39+
FROM base
40+
41+
USER root
42+
43+
WORKDIR /usr/src/app
44+
45+
COPY --from=deps /usr/src/app/node_modules ./node_modules
46+
COPY actions/lint-pr-title/src ./actions/lint-pr-title/src
47+
COPY actions/lint-pr-title/package.json ./actions/lint-pr-title/
48+
COPY actions/lint-pr-title/commitlint.config.js ./actions/lint-pr-title/
49+
50+
WORKDIR /usr/src/app/actions/lint-pr-title
2851

29-
ENTRYPOINT [ "bun", "run", "index.ts" ]
52+
ENTRYPOINT [ "bun", "run", "src/index.ts" ]

actions/lint-pr-title/action.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,31 @@ inputs:
1515
runs:
1616
using: "composite"
1717
steps:
18+
- name: Checkout shared-workflows repository
19+
env:
20+
action_repo: "${{ github.action_repository || 'grafana/shared-workflows' }}"
21+
action_ref: ${{ github.action_ref }}
22+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
23+
with:
24+
repository: ${{ env.action_repo }}
25+
ref: ${{ env.action_ref }}
26+
path: _shared-workflows-lint-pr-title
27+
persist-credentials: false
28+
1829
- name: Install bun package manager
1930
uses: oven-sh/setup-bun@735343b667d3e6f658f44d0eca948eb6282f2b76 # v2.0.2
2031
with:
21-
bun-version-file: actions/lint-pr-title/.bun-version
32+
bun-version-file: _shared-workflows-lint-pr-title/.bun-version
2233

2334
- name: Install dependencies
2435
shell: sh
25-
working-directory: ${{ github.action_path }}
36+
working-directory: _shared-workflows-lint-pr-title
2637
run: |
27-
bun install --frozen-lockfile --production
38+
bun install --frozen-lockfile --production --filter lint-pr-title
2839
2940
- name: Lint PR title
3041
shell: sh
31-
working-directory: ${{ github.action_path }}
42+
working-directory: _shared-workflows-lint-pr-title/actions/lint-pr-title
3243
env:
3344
GITHUB_TOKEN: ${{ github.token }}
3445
INPUT_CONFIG_PATH: ${{ inputs.config-path }}

0 commit comments

Comments
 (0)