Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/readme/imgs/setup_repository_secret.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .github/readme/imgs/setup_repository_secret.light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .github/readme/partials/documentation/setup/action.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ on:
jobs:
github-metrics:
runs-on: ubuntu-latest
environment:
name: production
permissions:
contents: write
steps:
Expand Down
41 changes: 6 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions source/plugins/habits/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down
17 changes: 12 additions & 5 deletions source/plugins/languages/analyzer/analyzer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -86,21 +87,27 @@ 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)
}
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
}
Expand Down Expand Up @@ -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}`)
}
}
}