From d3501121aa0c918c3afd8f6240e1ba5719505989 Mon Sep 17 00:00:00 2001 From: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Date: Tue, 21 Jul 2026 17:39:27 +0200 Subject: [PATCH] chore(ci): add prettier formatter Add prettier workflow Reformat files js, mjs, json, md & yml Remove eclint workflow Exclude auto-generated TOC contents --- .github/ISSUE_TEMPLATE/1-bug-report.md | 9 +- .github/ISSUE_TEMPLATE/2-feature-request.md | 1 - .github/PULL_REQUEST_TEMPLATE.md | 1 - .github/dependabot.yml | 10 +- .github/workflows/automatic-updates.yml | 8 +- .github/workflows/build-test.yml | 12 +- .github/workflows/doctoc.yml | 6 +- .github/workflows/markdown-link-check.yml | 6 +- .github/workflows/missing-checksum.yml | 4 +- .github/workflows/official-pr.yml | 14 +- .../workflows/{eclint.yml => prettier.yml} | 7 +- .github/workflows/scorecard.yml | 10 +- .github/workflows/shfmt.yml | 4 +- .prettierrc.json | 11 ++ CONTRIBUTING.md | 3 +- GOVERNANCE.md | 2 +- README.md | 16 +- build-automation.mjs | 87 +++++++---- docs/BestPractices.md | 2 + genMatrix.js | 59 ++++---- stackbrew.js | 141 ++++++++++-------- 21 files changed, 239 insertions(+), 174 deletions(-) rename .github/workflows/{eclint.yml => prettier.yml} (74%) create mode 100644 .prettierrc.json diff --git a/.github/ISSUE_TEMPLATE/1-bug-report.md b/.github/ISSUE_TEMPLATE/1-bug-report.md index d8ea9da3b4..3ab06a2858 100644 --- a/.github/ISSUE_TEMPLATE/1-bug-report.md +++ b/.github/ISSUE_TEMPLATE/1-bug-report.md @@ -11,10 +11,10 @@ Please fill in as much of the template below as you're able. ## Environment -* **Platform**: -* **Docker Version**: -* **Node.js Version**: -* **Image Tag**: +- **Platform**: +- **Docker Version**: +- **Node.js Version**: +- **Image Tag**: ## Expected Behavior @@ -45,4 +45,3 @@ Tell us about the steps you took to encounter this bug with the image. - diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.md b/.github/ISSUE_TEMPLATE/2-feature-request.md index 31a875664e..5fbb518557 100644 --- a/.github/ISSUE_TEMPLATE/2-feature-request.md +++ b/.github/ISSUE_TEMPLATE/2-feature-request.md @@ -26,4 +26,3 @@ Please describe the desired behavior. - diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6fadc5bdf3..31e3e40c4e 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -51,4 +51,3 @@ If you're unsure about any of these, don't hesitate to ask. We're here to help! - [ ] I have updated the documentation accordingly. - [ ] I have read the **CONTRIBUTING.md** document. - [ ] All new and existing tests passed. - diff --git a/.github/dependabot.yml b/.github/dependabot.yml index afb98ae0c7..3b4bef6fe3 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,7 +1,7 @@ version: 2 updates: -- package-ecosystem: github-actions - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/automatic-updates.yml b/.github/workflows/automatic-updates.yml index 950a950ce9..279f09004b 100644 --- a/.github/workflows/automatic-updates.yml +++ b/.github/workflows/automatic-updates.yml @@ -3,7 +3,7 @@ name: Automatically update Docker image versions on: workflow_dispatch: schedule: - - cron: "*/15 * * * *" + - cron: '*/15 * * * *' jobs: build: @@ -29,11 +29,11 @@ jobs: uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 with: token: ${{ secrets.GH_API_TOKEN }} - author: "Node.js GitHub Bot " + author: 'Node.js GitHub Bot ' branch: update-branch base: main - commit-message: "feat: Node.js ${{ steps.updt.outputs.result }}" - title: "feat: Node.js ${{ steps.updt.outputs.result }}" + commit-message: 'feat: Node.js ${{ steps.updt.outputs.result }}' + title: 'feat: Node.js ${{ steps.updt.outputs.result }}' delete-branch: true team-reviewers: | nodejs/docker diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 925b6747bf..3217dbfdea 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -3,17 +3,17 @@ name: build-test on: push: paths: - - "**/Dockerfile" - - "**/docker-entrypoint.sh" + - '**/Dockerfile' + - '**/docker-entrypoint.sh' - genMatrix.js - - ".github/workflows/build-test.yml" + - '.github/workflows/build-test.yml' pull_request: paths: - - "**/Dockerfile" - - "**/docker-entrypoint.sh" + - '**/Dockerfile' + - '**/docker-entrypoint.sh' - genMatrix.js - - ".github/workflows/build-test.yml" + - '.github/workflows/build-test.yml' jobs: gen-matrix: diff --git a/.github/workflows/doctoc.yml b/.github/workflows/doctoc.yml index f511eeab7a..fb347ac22a 100644 --- a/.github/workflows/doctoc.yml +++ b/.github/workflows/doctoc.yml @@ -3,9 +3,9 @@ name: Check generated TOCs on: pull_request: paths: - - "README.md" - - "docs/BestPractices.md" - - ".github/workflows/doctoc.yml" + - 'README.md' + - 'docs/BestPractices.md' + - '.github/workflows/doctoc.yml' permissions: contents: read diff --git a/.github/workflows/markdown-link-check.yml b/.github/workflows/markdown-link-check.yml index 17e6986200..53abd10a6f 100644 --- a/.github/workflows/markdown-link-check.yml +++ b/.github/workflows/markdown-link-check.yml @@ -3,9 +3,9 @@ name: Check Markdown links on: pull_request: paths: - - "**/*.md" - - "markdown_link_check_config.json" - - ".github/workflows/markdown-link-check.yml" + - '**/*.md' + - 'markdown_link_check_config.json' + - '.github/workflows/markdown-link-check.yml' permissions: contents: read diff --git a/.github/workflows/missing-checksum.yml b/.github/workflows/missing-checksum.yml index c9112a8123..fc27e1f2ce 100644 --- a/.github/workflows/missing-checksum.yml +++ b/.github/workflows/missing-checksum.yml @@ -3,8 +3,8 @@ name: Check Alpine CHECKSUM on: pull_request: paths: - - ".github/workflows/missing-checksum.yml" - - "**/alpine*/Dockerfile" + - '.github/workflows/missing-checksum.yml' + - '**/alpine*/Dockerfile' permissions: contents: read diff --git a/.github/workflows/official-pr.yml b/.github/workflows/official-pr.yml index 3d1831f36b..c8ad563f52 100644 --- a/.github/workflows/official-pr.yml +++ b/.github/workflows/official-pr.yml @@ -6,11 +6,11 @@ on: - closed paths: - - ".github/workflows/official-pr.yml" - - "**/Dockerfile" - - "**/docker-entrypoint.sh" - - "versions.json" - - "stackbrew.js" + - '.github/workflows/official-pr.yml' + - '**/Dockerfile' + - '**/docker-entrypoint.sh' + - 'versions.json' + - 'stackbrew.js' jobs: pr: @@ -46,8 +46,8 @@ jobs: push-to-fork: nodejs/official-images path: official-images branch: node - commit-message: "Node: ${{ github.event.pull_request.title }}" - title: "Node: ${{ github.event.pull_request.title }}" + commit-message: 'Node: ${{ github.event.pull_request.title }}' + title: 'Node: ${{ github.event.pull_request.title }}' body: | Pull Request: ${{ github.event.pull_request.html_url }} @PeterDaveHello @SimenB @nschonni @rafaelgss @mcollina diff --git a/.github/workflows/eclint.yml b/.github/workflows/prettier.yml similarity index 74% rename from .github/workflows/eclint.yml rename to .github/workflows/prettier.yml index 29c02759ea..4eb7a39df7 100644 --- a/.github/workflows/eclint.yml +++ b/.github/workflows/prettier.yml @@ -1,4 +1,4 @@ -name: Test Whitespace and line endings +name: Check Prettier formatting on: [pull_request] @@ -6,12 +6,11 @@ permissions: contents: read jobs: - eclint: + prettier: runs-on: ubuntu-latest steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: 'lts/*' - - run: npm i -g eclint - - run: eclint check + - run: npx prettier@3.9.5 --check . diff --git a/.github/workflows/scorecard.yml b/.github/workflows/scorecard.yml index b984e9cc8e..4b152920f5 100644 --- a/.github/workflows/scorecard.yml +++ b/.github/workflows/scorecard.yml @@ -12,7 +12,7 @@ on: schedule: - cron: '30 12 * * 6' push: - branches: [ "main" ] + branches: ['main'] # Declare default permissions as read only. permissions: read-all @@ -31,12 +31,12 @@ jobs: # actions: read steps: - - name: "Checkout code" + - name: 'Checkout code' uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - name: "Run analysis" + - name: 'Run analysis' uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3 with: results_file: results.sarif @@ -58,7 +58,7 @@ jobs: # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # format to the repository Actions tab. - - name: "Upload artifact" + - name: 'Upload artifact' uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: name: SARIF file @@ -67,7 +67,7 @@ jobs: # Upload the results to GitHub's code scanning dashboard (optional). # Commenting out will disable upload of results to your repo's Code Scanning dashboard - - name: "Upload to code-scanning" + - name: 'Upload to code-scanning' uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1 with: sarif_file: results.sarif diff --git a/.github/workflows/shfmt.yml b/.github/workflows/shfmt.yml index ae4e9c5879..33aabb08d5 100644 --- a/.github/workflows/shfmt.yml +++ b/.github/workflows/shfmt.yml @@ -3,8 +3,8 @@ name: Check Shell scripts on: pull_request: paths: - - "**/*.sh" - - ".github/workflows/shfmt.yml" + - '**/*.sh' + - '.github/workflows/shfmt.yml' permissions: contents: read diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000000..76f1765fbb --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,11 @@ +{ + "singleQuote": true, + "overrides": [ + { + "files": "versions.json", + "options": { + "printWidth": 38 + } + } + ] +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e7b53497a..14f8d6d20e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,7 @@ the Node.js TSC as final arbiter. ## Discussion Areas + You can use Node.js channels (prefixed by `#nodejs-`) in the [OpenJSF Slack](https://slack-invite.openjsf.org/) workspace for discussions. @@ -73,4 +74,4 @@ This task is undertaken by members of the repo team above. ## Adding dependencies to the base images -NodeJS is a big ecosystem with a variety of different use cases. The docker images for node are designed to provide the minimum for running core node. Additional dependencies (including dependencies for npm or yarn such as git) will not be included in these base images and will need to be included in descendent image. +NodeJS is a big ecosystem with a variety of different use cases. The docker images for node are designed to provide the minimum for running core node. Additional dependencies (including dependencies for npm or yarn such as git) will not be included in these base images and will need to be included in descendent image. diff --git a/GOVERNANCE.md b/GOVERNANCE.md index 47759b9993..3b261b1591 100644 --- a/GOVERNANCE.md +++ b/GOVERNANCE.md @@ -54,7 +54,7 @@ For governance, membership, major policy, or contentious technical changes: 1. Open an issue or PR describing the decision and proposed outcome. 2. Allow time for async feedback (normally at least 5 days). 3. If no unresolved objections remain, a maintainer may merge/close with a - summary. + summary. If a final decision cannot be made using Consensus Seeking, the issue should be escalated to the Node.js TSC (for example by requesting `tsc-agenda`). diff --git a/README.md b/README.md index 1df2827a21..fd9c72a16b 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,12 @@ [**node - Docker Official Images on Docker Hub**](https://hub.docker.com/_/node) -[![GitHub issues](https://img.shields.io/github/issues/nodejs/docker-node.svg "GitHub issues")](https://github.com/nodejs/docker-node) -[![GitHub stars](https://img.shields.io/github/stars/nodejs/docker-node.svg "GitHub stars")](https://github.com/nodejs/docker-node) +[![GitHub issues](https://img.shields.io/github/issues/nodejs/docker-node.svg 'GitHub issues')](https://github.com/nodejs/docker-node) +[![GitHub stars](https://img.shields.io/github/stars/nodejs/docker-node.svg 'GitHub stars')](https://github.com/nodejs/docker-node) The official Node.js docker image, made with love by the node community. + ## Table of Contents @@ -42,6 +43,7 @@ The official Node.js docker image, made with love by the node community. - [Emeritus](#emeritus) + ## What is Node.js? @@ -75,16 +77,16 @@ If you prefer Docker Compose: ```yml services: node: - image: "node:24" - user: "node" + image: 'node:24' + user: 'node' working_dir: /home/node/app environment: - NODE_ENV=production volumes: - ./:/home/node/app ports: # use if it is necessary to expose the container to the host machine - - "8888:8888" - command: ["npm", "start"] + - '8888:8888' + command: ['npm', 'start'] ``` You can then run using Docker Compose: @@ -230,7 +232,7 @@ This image is based on version 13 of This image does not contain the common packages contained in the default tag and only contains the minimal packages needed to run `node`. Unless you are working -in an environment where *only* the Node.js image will be deployed and you have +in an environment where _only_ the Node.js image will be deployed and you have space constraints, we highly recommend using the default image of this repository. diff --git a/build-automation.mjs b/build-automation.mjs index ba296d1ed4..f5760ec8fb 100644 --- a/build-automation.mjs +++ b/build-automation.mjs @@ -1,6 +1,6 @@ -import { promisify } from "util"; +import { promisify } from 'util'; -import child_process from "child_process"; +import child_process from 'child_process'; const exec = promisify(child_process.exec); @@ -9,23 +9,33 @@ const exec = promisify(child_process.exec); // and returns whether we should update or not const checkIfThereAreNewVersions = async (github) => { try { - const { stdout: versionsOutput } = await exec(". ./functions.sh && get_versions", { shell: "bash" }); + const { stdout: versionsOutput } = await exec( + '. ./functions.sh && get_versions', + { shell: 'bash' }, + ); - const supportedVersions = versionsOutput.trim().split(" "); + const supportedVersions = versionsOutput.trim().split(' '); let latestSupportedVersions = {}; for (let supportedVersion of supportedVersions) { const { stdout } = await exec(`ls ${supportedVersion}`); - const { stdout: fullVersionOutput } = await exec(`. ./functions.sh && get_full_version ./${supportedVersion}/${stdout.trim().split("\n")[0]}`, { shell: "bash" }); + const { stdout: fullVersionOutput } = await exec( + `. ./functions.sh && get_full_version ./${supportedVersion}/${stdout.trim().split('\n')[0]}`, + { shell: 'bash' }, + ); console.log(fullVersionOutput); - latestSupportedVersions[supportedVersion] = { fullVersion: fullVersionOutput.trim() }; + latestSupportedVersions[supportedVersion] = { + fullVersion: fullVersionOutput.trim(), + }; } - const { data: availableVersionsJson } = await github.request('https://nodejs.org/download/release/index.json'); + const { data: availableVersionsJson } = await github.request( + 'https://nodejs.org/download/release/index.json', + ); // filter only more recent versions of availableVersionsJson for each major version in latestSupportedVersions' keys // e.g. if latestSupportedVersions = { "12": "12.22.10", "14": "14.19.0", "16": "16.14.0", "17": "17.5.0" } @@ -35,20 +45,32 @@ const checkIfThereAreNewVersions = async (github) => { let filteredNewerVersions = {}; for (let availableVersion of availableVersionsJson) { - const [availableMajor, availableMinor, availablePatch] = availableVersion.version.split("v")[1].split("."); + const [availableMajor, availableMinor, availablePatch] = + availableVersion.version.split('v')[1].split('.'); if (latestSupportedVersions[availableMajor] == null) { continue; } - const [_latestMajor, latestMinor, latestPatch] = latestSupportedVersions[availableMajor].fullVersion.split("."); - if (latestSupportedVersions[availableMajor] && (Number(availableMinor) > Number(latestMinor) || (availableMinor === latestMinor && Number(availablePatch) > Number(latestPatch)))) { - filteredNewerVersions[availableMajor] = { fullVersion: `${availableMajor}.${availableMinor}.${availablePatch}` }; + const [_latestMajor, latestMinor, latestPatch] = + latestSupportedVersions[availableMajor].fullVersion.split('.'); + if ( + latestSupportedVersions[availableMajor] && + (Number(availableMinor) > Number(latestMinor) || + (availableMinor === latestMinor && + Number(availablePatch) > Number(latestPatch))) + ) { + filteredNewerVersions[availableMajor] = { + fullVersion: `${availableMajor}.${availableMinor}.${availablePatch}`, + }; } } return { - shouldUpdate: Object.keys(filteredNewerVersions).length > 0 && JSON.stringify(filteredNewerVersions) !== JSON.stringify(latestSupportedVersions), + shouldUpdate: + Object.keys(filteredNewerVersions).length > 0 && + JSON.stringify(filteredNewerVersions) !== + JSON.stringify(latestSupportedVersions), versions: filteredNewerVersions, - } + }; } catch (error) { console.error(error); process.exit(1); @@ -59,12 +81,18 @@ const checkIfThereAreNewVersions = async (github) => { // and returns relevant information const checkForMuslVersionsAndSecurityReleases = async (github, versions) => { try { - const { data: unofficialBuildsIndexText } = await github.request('https://unofficial-builds.nodejs.org/download/release/index.json'); + const { data: unofficialBuildsIndexText } = await github.request( + 'https://unofficial-builds.nodejs.org/download/release/index.json', + ); for (let version of Object.keys(versions)) { - const buildVersion = unofficialBuildsIndexText.find(indexVersion => indexVersion.version === `v${versions[version].fullVersion}`); + const buildVersion = unofficialBuildsIndexText.find( + (indexVersion) => + indexVersion.version === `v${versions[version].fullVersion}`, + ); - versions[version].muslBuildExists = buildVersion?.files.includes("linux-x64-musl") ?? false; + versions[version].muslBuildExists = + buildVersion?.files.includes('linux-x64-musl') ?? false; versions[version].isSecurityRelease = buildVersion?.security ?? false; } return versions; @@ -74,30 +102,37 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => { } }; -export default async function(github) { -// if there are no new versions, exit gracefully -// if there are new versions, -// check for musl builds -// then run update.sh +export default async function (github) { + // if there are no new versions, exit gracefully + // if there are new versions, + // check for musl builds + // then run update.sh const { shouldUpdate, versions } = await checkIfThereAreNewVersions(github); if (!shouldUpdate) { - console.log("No new versions found. No update required."); + console.log('No new versions found. No update required.'); process.exit(0); } else { - const newVersions = await checkForMuslVersionsAndSecurityReleases(github, versions); + const newVersions = await checkForMuslVersionsAndSecurityReleases( + github, + versions, + ); let updatedVersions = []; for (const [version, newVersion] of Object.entries(newVersions)) { if (newVersion.muslBuildExists) { - const { stdout } = await exec(`./update.sh ${newVersion.isSecurityRelease ? "-s " : ""}${version}`); + const { stdout } = await exec( + `./update.sh ${newVersion.isSecurityRelease ? '-s ' : ''}${version}`, + ); console.log(stdout); updatedVersions.push(newVersion.fullVersion); } else { - console.log(`There's no musl build for version ${newVersion.fullVersion} yet.`); + console.log( + `There's no musl build for version ${newVersion.fullVersion} yet.`, + ); process.exit(0); } } - const { stdout } = (await exec(`git diff`)); + const { stdout } = await exec(`git diff`); console.log(stdout); return updatedVersions.join(', '); diff --git a/docs/BestPractices.md b/docs/BestPractices.md index ab60375baf..de54618467 100644 --- a/docs/BestPractices.md +++ b/docs/BestPractices.md @@ -1,5 +1,6 @@ # Docker and Node.js Best Practices + ## Table of Contents @@ -16,6 +17,7 @@ - [Smaller images without npm/yarn](#smaller-images-without-npmyarn) + ## Environment Variables diff --git a/genMatrix.js b/genMatrix.js index dc76724328..fc10f8d994 100644 --- a/genMatrix.js +++ b/genMatrix.js @@ -2,36 +2,36 @@ const path = require('path'); const fs = require('fs'); -const testFiles = [ - 'genMatrix.js', - '.github/workflows/build-test.yml', -]; +const testFiles = ['genMatrix.js', '.github/workflows/build-test.yml']; const nodeDirRegex = /^\d+$/; -const areTestFilesChanged = (changedFiles) => changedFiles - .some((file) => testFiles.includes(file)); +const areTestFilesChanged = (changedFiles) => + changedFiles.some((file) => testFiles.includes(file)); // Returns a list of the child directories in the given path -const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true }) - .filter((dirent) => dirent.isDirectory()) - .map(({ name }) => path.resolve(parent, name)); +const getChildDirectories = (parent) => + fs + .readdirSync(parent, { withFileTypes: true }) + .filter((dirent) => dirent.isDirectory()) + .map(({ name }) => path.resolve(parent, name)); -const getNodeVersionDirs = (base) => getChildDirectories(base) - .filter((childPath) => nodeDirRegex.test(path.basename(childPath))); +const getNodeVersionDirs = (base) => + getChildDirectories(base).filter((childPath) => + nodeDirRegex.test(path.basename(childPath)), + ); // Returns the paths of Dockerfiles that are at: base/*/Dockerfile -const getDockerfilesInChildDirs = (base) => getChildDirectories(base) - .map((childDir) => path.resolve(childDir, 'Dockerfile')); +const getDockerfilesInChildDirs = (base) => + getChildDirectories(base).map((childDir) => + path.resolve(childDir, 'Dockerfile'), + ); -const getAllDockerfiles = (base) => getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs); +const getAllDockerfiles = (base) => + getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs); const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => { - const files = [ - ...filesAdded, - ...filesModified, - ...filesRenamed, - ]; + const files = [...filesAdded, ...filesModified, ...filesRenamed]; // If the test files were changed, include everything if (areTestFilesChanged(files)) { @@ -39,21 +39,20 @@ const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => { return getAllDockerfiles(__dirname); } - const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile')); + const modifiedDockerfiles = files.filter((file) => + file.endsWith('/Dockerfile'), + ); // Get Dockerfiles affected by modified docker-entrypoint.sh files const entrypointAffectedDockerfiles = files .filter((file) => file.endsWith('/docker-entrypoint.sh')) .map((file) => path.resolve(path.dirname(file), 'Dockerfile')); - return [ - ...modifiedDockerfiles, - ...entrypointAffectedDockerfiles, - ]; + return [...modifiedDockerfiles, ...entrypointAffectedDockerfiles]; }; -const getFullNodeVersionFromDockerfile = (file) => fs.readFileSync(file, 'utf8') - .match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1]; +const getFullNodeVersionFromDockerfile = (file) => + fs.readFileSync(file, 'utf8').match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1]; const getDockerfileMatrixEntry = (file) => { const [variant] = path.dirname(file).split(path.sep).slice(-1); @@ -67,14 +66,14 @@ const getDockerfileMatrixEntry = (file) => { }; const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => { - const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))]; + const dockerfiles = [ + ...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed)), + ]; const entries = dockerfiles.map(getDockerfileMatrixEntry); // Return null if there are no entries so we can skip the matrix step - return entries.length - ? { include: entries } - : null; + return entries.length ? { include: entries } : null; }; module.exports = generateBuildMatrix; diff --git a/stackbrew.js b/stackbrew.js index 9d82f310f1..5a00e332ee 100755 --- a/stackbrew.js +++ b/stackbrew.js @@ -6,8 +6,9 @@ const path = require('path'); // Grab last git commit function getCommitHasForPath(path) { return require('child_process') - .execSync(`git log -1 --format=%H HEAD -- ${path}`) - .toString().trim() + .execSync(`git log -1 --format=%H HEAD -- ${path}`) + .toString() + .trim(); } const stackbrewPath = path.basename(__filename); @@ -23,11 +24,11 @@ GitFetch: refs/heads/main\n`; const config = require('./versions.json'); -const versions = Object.keys(config).reverse() +const versions = Object.keys(config).reverse(); -let midnight = new Date() -midnight.setHours(0, 0, 0, 0) -const now = midnight.getTime() +let midnight = new Date(); +midnight.setHours(0, 0, 0, 0); +const now = midnight.getTime(); const alpineRE = new RegExp(/alpine*/); const slimRE = new RegExp(/\*-slim/); let foundLTS = false; @@ -37,117 +38,135 @@ for (const version of versions) { let lts = new Date(`${config[version].lts}T00:00:00.00`).getTime(); let isCurrent = foundCurrent ? false : isNaN(lts) || lts >= now; foundCurrent = isCurrent || foundCurrent; - let isLTS = foundLTS ? false : (now >= lts); + let isLTS = foundLTS ? false : now >= lts; foundLTS = isLTS || foundLTS; - let codename = config[version].codename - let defaultAlpine = config[version]['alpine-default'] - let defaultDebian = config[version]['debian-default'] - let variants = config[version].variants + let codename = config[version].codename; + let defaultAlpine = config[version]['alpine-default']; + let defaultDebian = config[version]['debian-default']; + let variants = config[version].variants; for (const variant in variants) { let dockerfilePath = path.join(version, variant, 'Dockerfile'); - let isAlpine = alpineRE.test(variant) - let isSlim = slimRE.test(variant) - let isDefaultSlim = new RegExp(`${defaultDebian}-slim`).test(variant) + let isAlpine = alpineRE.test(variant); + let isSlim = slimRE.test(variant); + let isDefaultSlim = new RegExp(`${defaultDebian}-slim`).test(variant); // Get full version from the Dockerfile - let dockerfile = fs.readFileSync(dockerfilePath, 'utf-8') - let fullVersion = dockerfile.match(/ENV NODE_VERSION=(?\d+)\.(?\d+)\.(?\d+)/) + let dockerfile = fs.readFileSync(dockerfilePath, 'utf-8'); + let fullVersion = dockerfile.match( + /ENV NODE_VERSION=(?\d+)\.(?\d+)\.(?\d+)/, + ); let tags = [ `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-${variant}`, `${fullVersion.groups.major}.${fullVersion.groups.minor}-${variant}`, `${fullVersion.groups.major}-${variant}`, - ] + ]; if (codename) { - tags.push(`${codename}-${variant}`) + tags.push(`${codename}-${variant}`); } if (variant === defaultAlpine) { - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`) - tags.push(`${fullVersion.groups.major}-alpine`) + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`, + ); + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`, + ); + tags.push(`${fullVersion.groups.major}-alpine`); if (codename) { - tags.push(`${codename}-alpine`) + tags.push(`${codename}-alpine`); } } if (variant === defaultDebian) { - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}`) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}`) - tags.push(`${fullVersion.groups.major}`) + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}`, + ); + tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}`); + tags.push(`${fullVersion.groups.major}`); if (isSlim) { - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`) - tags.push(`${fullVersion.groups.major}-slim`) + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`, + ); + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`, + ); + tags.push(`${fullVersion.groups.major}-slim`); } if (codename) { - tags.push(`${codename}`) + tags.push(`${codename}`); } } if (isDefaultSlim) { - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`) - tags.push(`${fullVersion.groups.major}-slim`) + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`, + ); + tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`); + tags.push(`${fullVersion.groups.major}-slim`); if (codename) { - tags.push(`${codename}-slim`) + tags.push(`${codename}-slim`); } } if (isCurrent) { if (variant === defaultAlpine) { - tags.push(variant) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`) - tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`) - tags.push(`${fullVersion.groups.major}-alpine`) - tags.push('alpine') - tags.push('current-alpine') + tags.push(variant); + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`, + ); + tags.push( + `${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`, + ); + tags.push(`${fullVersion.groups.major}-alpine`); + tags.push('alpine'); + tags.push('current-alpine'); } if (variant === defaultDebian) { - tags.push(variant) - tags.push('latest') - tags.push('current') + tags.push(variant); + tags.push('latest'); + tags.push('current'); } if (isAlpine) { - tags.push(`${variant}`) - tags.push(`current-${variant}`) + tags.push(`${variant}`); + tags.push(`current-${variant}`); } if (!isAlpine) { - tags.push(`${variant}`) - tags.push(`current-${variant}`) + tags.push(`${variant}`); + tags.push(`current-${variant}`); } if (isDefaultSlim) { - tags.push('slim') - tags.push('current-slim') + tags.push('slim'); + tags.push('current-slim'); } } if (isLTS) { - tags.push(`lts-${variant}`) + tags.push(`lts-${variant}`); if (variant === defaultDebian) { - tags.push('lts') + tags.push('lts'); if (codename) { - tags.push(`lts-${codename}`) + tags.push(`lts-${codename}`); } } if (isDefaultSlim) { - tags.push(`lts-slim`) + tags.push(`lts-slim`); } if (variant === defaultAlpine) { - tags.push(`lts-alpine`) + tags.push(`lts-alpine`); } } // remove duplicates - tags = tags.filter((x, i, a) => a.indexOf(x) == i) - tags = tags.sort() - let directory = `${version}/${variant}` - stackbrew += `\nTags: ${tags.join(', ')}\n` - stackbrew += `Architectures: ${config[version].variants[variant].join(', ')}\n` - stackbrew += `GitCommit: ${getCommitHasForPath(directory)}\n` - stackbrew += `Directory: ${directory}\n` + tags = tags.filter((x, i, a) => a.indexOf(x) == i); + tags = tags.sort(); + let directory = `${version}/${variant}`; + stackbrew += `\nTags: ${tags.join(', ')}\n`; + stackbrew += `Architectures: ${config[version].variants[variant].join(', ')}\n`; + stackbrew += `GitCommit: ${getCommitHasForPath(directory)}\n`; + stackbrew += `Directory: ${directory}\n`; } } // output -console.log(stackbrew) +console.log(stackbrew);