diff --git a/.github/readme/imgs/setup_repository_secret.dark.png b/.github/readme/imgs/setup_repository_secret.dark.png index 6cae665e4c0..c1bab0ef916 100644 Binary files a/.github/readme/imgs/setup_repository_secret.dark.png and b/.github/readme/imgs/setup_repository_secret.dark.png differ diff --git a/.github/readme/imgs/setup_repository_secret.light.png b/.github/readme/imgs/setup_repository_secret.light.png index cdecab517fe..f4d54fcfbdd 100644 Binary files a/.github/readme/imgs/setup_repository_secret.light.png and b/.github/readme/imgs/setup_repository_secret.light.png differ diff --git a/.github/readme/partials/documentation/setup/action.md b/.github/readme/partials/documentation/setup/action.md index e066c398359..320134ce2be 100644 --- a/.github/readme/partials/documentation/setup/action.md +++ b/.github/readme/partials/documentation/setup/action.md @@ -68,6 +68,8 @@ on: jobs: github-metrics: runs-on: ubuntu-latest + environment: + name: production permissions: contents: write steps: diff --git a/Dockerfile b/Dockerfile index 3ff5209a48a..ccc60fdccbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,8 @@ -# Base image -FROM node:20-bookworm-slim +# Use official pre-built image as base, only overlay patched file +FROM ghcr.io/lowlighter/metrics:v3.34 -# Copy repository -COPY . /metrics -WORKDIR /metrics +# Apply fix: guard against null commit entries in habits plugin +COPY source/plugins/habits/index.mjs /metrics/source/plugins/habits/index.mjs -# Setup -RUN chmod +x /metrics/source/app/action/index.mjs \ - # Install latest chrome dev package, fonts to support major charsets and skip chromium download on puppeteer install - # Based on https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker - && apt-get update \ - && apt-get install -y wget gnupg ca-certificates libgconf-2-4 \ - && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ - && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \ - && apt-get update \ - && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libx11-xcb1 libxtst6 lsb-release --no-install-recommends \ - # Install deno for miscellaneous scripts - && apt-get install -y curl unzip \ - && curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL=/usr/local sh \ - # Install ruby to support github licensed gem - && apt-get install -y ruby-full git g++ cmake pkg-config libssl-dev \ - && gem install licensed \ - # Install python for node-gyp - && apt-get install -y python3 \ - # Clean apt/lists - && rm -rf /var/lib/apt/lists/* \ - # Install node modules and rebuild indexes - && npm ci \ - && npm run build - -# Environment variables -ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true -ENV PUPPETEER_BROWSER_PATH "google-chrome-stable" - -# Execute GitHub action -ENTRYPOINT node /metrics/source/app/action/index.mjs +# Re-use original entrypoint +ENTRYPOINT ["/bin/sh", "-c", "node /metrics/source/app/action/index.mjs"] diff --git a/source/plugins/habits/index.mjs b/source/plugins/habits/index.mjs index 3a1a437d602..e4175ba5c26 100644 --- a/source/plugins/habits/index.mjs +++ b/source/plugins/habits/index.mjs @@ -48,6 +48,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled ...await Promise.allSettled( commits .flatMap(({payload}) => payload.commits) + .filter(commit => commit) .filter(({author}) => data.shared["commits.authoring"].filter(authoring => author?.login?.toLocaleLowerCase().includes(authoring) || author?.email?.toLocaleLowerCase().includes(authoring) || author?.name?.toLocaleLowerCase().includes(authoring)).length) .map(async commit => (await rest.request(commit)).data.files), ), diff --git a/source/plugins/languages/analyzer/analyzer.mjs b/source/plugins/languages/analyzer/analyzer.mjs index 529a367e5cf..e0042cb1dc3 100644 --- a/source/plugins/languages/analyzer/analyzer.mjs +++ b/source/plugins/languages/analyzer/analyzer.mjs @@ -4,6 +4,7 @@ import os from "os" import paths from "path" import git from "simple-git" import { filters } from "../../../app/metrics/utils.mjs" +import core from "@actions/core" /**Analyzer */ export class Analyzer { @@ -86,13 +87,19 @@ export class Analyzer { /**Clone a repository */ async clone(repository) { const {repo, branch, path} = this.parse(repository) - let url = /^https?:\/\//.test(repo) ? repo : `https://github.com/${repo}` + let token + + if (process.env.GITHUB_ACTIONS) { + token = core.getInput("token") + } + + let url = /^https?:\/\//.test(repo) ? repo : `https://${token}@github.com/${repo}` try { - this.debug(`cloning ${url} to ${path}`) + this.debug(`cloning https://github.com/${repo} to ${path}`) await fs.rm(path, {recursive: true, force: true}) await fs.mkdir(path, {recursive: true}) await git(path).clone(url, ".", ["--single-branch"]).status() - this.debug(`cloned ${url} to ${path}`) + this.debug(`cloned https://github.com/${repo} to ${path}`) if (branch) { this.debug(`switching to branch ${branch} for ${repo}`) await git(path).branch(branch) @@ -100,7 +107,7 @@ export class Analyzer { return true } catch (error) { - this.debug(`failed to clone ${url} (${error})`) + this.debug(`failed to clone https://github.com/${repo} (${error})`) this.clean(path) return false } @@ -176,4 +183,4 @@ export class Analyzer { debug(message) { return console.debug(`metrics/compute/${this.login}/plugins > languages > ${this.constructor.name.replace(/([a-z])([A-Z])/, (_, a, b) => `${a} ${b.toLocaleLowerCase()}`).toLocaleLowerCase()} > ${message}`) } -} +} \ No newline at end of file