-
Notifications
You must be signed in to change notification settings - Fork 18
fix: install latest npm version for node 22 #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
schedule: | ||
- cron: "0 10 * * *" # everyday at 10am | ||
workflow_dispatch: | ||
pull_request_target: | ||
pull_request: | ||
branches: ["latest"] | ||
push: | ||
branches: ["latest"] | ||
|
@@ -20,6 +20,8 @@ jobs: | |
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v5 | ||
with: | ||
ref: ${{ github.head_ref || github.ref }} | ||
- name: Set imageName based on the repository name | ||
Comment on lines
21
to
25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainFix checkout for forked PRs (current ref override can break on forks). Using Apply this diff to split checkout into two steps and make it fork-safe while also fetching full history (helps tagging/metadata), and avoiding credentials on PRs: - - name: Check out the repo
- uses: actions/checkout@v5
- with:
- ref: ${{ github.head_ref || github.ref }}
+ - name: Check out PR (fork-safe)
+ if: ${{ github.event_name == 'pull_request' }}
+ uses: actions/checkout@v5
+ with:
+ repository: ${{ github.event.pull_request.head.repo.full_name }}
+ ref: ${{ github.event.pull_request.head.ref }}
+ fetch-depth: 0
+ persist-credentials: false
+ - name: Check out repo (non-PR)
+ if: ${{ github.event_name != 'pull_request' }}
+ uses: actions/checkout@v5
+ with:
+ ref: ${{ github.ref }}
+ fetch-depth: 0 You can validate this by opening a test PR from a fork and confirming the checkout step resolves the fork’s head repository/branch and proceeds to build. 🏁 Script executed: #!/usr/bin/env bash
set -e
echo "=== First 100 lines of .github/workflows/docker.yml ==="
if [ -f .github/workflows/docker.yml ]; then
sed -n '1,100p' .github/workflows/docker.yml
else
echo "File .github/workflows/docker.yml not found"
fi Length of output: 1699 Ensure fork-safe checkout in Pull Request workflows Using with:
ref: ${{ github.head_ref || github.ref }} will default to checking out the specified branch from the base repository ( Split the checkout into two conditional steps—one for PRs (explicitly pointing to the fork’s repo and branch, with full history and no credentials) and one for non-PRs—to guarantee correct behavior on forks: • Check out PR head (fork-safe) - name: Check out PR (fork-safe)
if: ${{ github.event_name == 'pull_request' }}
uses: actions/checkout@v5
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
persist-credentials: false • Check out default ref on non-PR events - name: Check out repo (non-PR)
if: ${{ github.event_name != 'pull_request' }}
uses: actions/checkout@v5
with:
ref: ${{ github.ref }}
fetch-depth: 0 This ensures that on a forked pull request you fetch from the correct repository and branch, and for pushes/tags you continue using the workflow’s default behavior (stackoverflow.com). 🤖 Prompt for AI Agents
|
||
id: step_one | ||
run: | | ||
|
@@ -46,5 +48,6 @@ jobs: | |
with: | ||
platforms: ${{ env.platforms }} | ||
push: ${{ github.event_name != 'pull_request' }} | ||
pull: true | ||
tags: ${{ steps.docker_meta.outputs.tags }} | ||
labels: ${{ steps.docker_meta.outputs.labels }} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,10 +18,11 @@ LABEL maintainer="[email protected]" \ | |||||||||||||||||||||
org.opencontainers.image.documentation="https://github.com/beevelop/docker-android-nodejs/blob/latest/README.md" \ | ||||||||||||||||||||||
org.opencontainers.image.source="https://github.com/beevelop/docker-android-nodejs.git" | ||||||||||||||||||||||
|
||||||||||||||||||||||
# Install Node.js using NodeSource repository | ||||||||||||||||||||||
RUN apt-get update && apt-get install -y curl ca-certificates && \ | ||||||||||||||||||||||
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \ | ||||||||||||||||||||||
apt-get install -y nodejs && \ | ||||||||||||||||||||||
# Install Node.js 22 with compatible npm using official Node.js binaries | ||||||||||||||||||||||
ENV NODE_VERSION=22.18.0 | ||||||||||||||||||||||
RUN apt-get update && apt-get install -y curl ca-certificates xz-utils && \ | ||||||||||||||||||||||
curl -fsSL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz | tar -xJ -C /usr/local --strip-components=1 && \ | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Hardcoded linux-x64 will break non-amd64 (e.g., arm64) builds — derive arch via TARGETARCH/uname and use it in the URL. This Dockerfile will fail or produce the wrong binary on arm64 or other platforms. Make it multi-arch friendly by mapping the docker buildx-provided TARGETARCH (or uname -m fallback) to Node’s archive naming. Apply this diff: - curl -fsSL https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz | tar -xJ -C /usr/local --strip-components=1 && \
+ arch="${TARGETARCH:-$(uname -m)}"; \
+ case "$arch" in \
+ x86_64|amd64) node_arch=x64 ;; \
+ aarch64|arm64) node_arch=arm64 ;; \
+ armv7l|armv7|armhf) node_arch=armv7l ;; \
+ *) echo "Unsupported architecture: $arch" >&2; exit 1 ;; \
+ esac; \
+ curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
+ | tar -xJ -C /usr/local --strip-components=1 && \ 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||
npm install -g npm@latest && \ | ||||||||||||||||||||||
npm install -g yarn && \ | ||||||||||||||||||||||
apt-get clean && \ | ||||||||||||||||||||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \ | ||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Good move: pull_request is safer than pull_request_target, but gate secret-using steps to avoid PR failures.
Switching to
pull_request
reduces token exposure from forks. However, secrets are not available onpull_request
from forks and same-repo PRs may still not need them. Make sure steps that require secrets (e.g., Docker Hub login) are skipped on PRs; otherwise the workflow can fail on forks due to missing inputs.I’ve added a separate comment with a targeted diff for the Docker Hub login step to gate it properly.
🏁 Script executed:
Length of output: 1641
Gate DockerHub login step to non-PR events
The DockerHub login currently runs on every
pull_request
, but GitHub does not expose secrets for forked PRs, causing the workflow to fail. Add anif
condition to skip the login when the event ispull_request
.• File:
.github/workflows/docker.yml
Location: around the “Login to DockerHub” step in
jobs.main.steps
Suggested diff:
- name: Login to DockerHub + if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }}
📝 Committable suggestion
🤖 Prompt for AI Agents