Skip to content

Commit 67654e6

Browse files
committed
init commit
0 parents  commit 67654e6

7 files changed

Lines changed: 679 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'Dockerfile'
9+
- 'convert-nuget.js'
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
jobs:
17+
publish:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout repo
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Log in to GitHub Container Registry
27+
uses: docker/login-action@v3
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
33+
- name: Extract metadata
34+
id: meta
35+
uses: docker/metadata-action@v5
36+
with:
37+
images: ghcr.io/semgrep/convert-nuget
38+
tags: |
39+
type=ref,event=branch
40+
type=sha,prefix={{branch}}-
41+
type=raw,value=latest,enable={{is_default_branch}}
42+
43+
- name: Build and push
44+
uses: docker/build-push-action@v5
45+
with:
46+
context: .
47+
push: true
48+
tags: ${{ steps.meta.outputs.tags }}
49+
labels: ${{ steps.meta.outputs.labels }}
50+

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Sample packages.config file
2+
packages.config
3+
4+
# Generated lock files
5+
packages.lock.json
6+

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Build on the official .NET SDK image (Debian-based)
2+
# Using 8.0 LTS for stability and long-term support
3+
FROM mcr.microsoft.com/dotnet/sdk:8.0
4+
5+
# Install Node.js (required for the script)
6+
RUN apt-get update && apt-get install -y --no-install-recommends curl \
7+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
8+
&& apt-get install -y --no-install-recommends nodejs \
9+
&& apt-get clean \
10+
&& rm -rf /var/lib/apt/lists/*
11+
12+
# Create a workspace and copy entrypoint script
13+
WORKDIR /tool
14+
COPY convert-nuget.js /tool/convert-nuget.js
15+
16+
RUN chmod +x /tool/convert-nuget.js
17+
18+
# Default entrypoint: process current working directory
19+
# The working directory should be mounted as a volume when running:
20+
# docker run -v "$(pwd):/workspace" -w /workspace <image> [options]
21+
ENTRYPOINT ["node", "/tool/convert-nuget.js"]

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2025 the copyright holders
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# convert-nuget
2+
3+
Recursively searches for `packages.config` files and converts each to `packages.lock.json`. The generated files are created in the same directory as each discovered `packages.config` file.
4+
5+
## Manual Usage
6+
7+
```bash
8+
node convert-nuget.js [--tfm <TFM>] [--root <DIR>]
9+
10+
# Example: scan from current directory
11+
node convert-nuget.js
12+
13+
# Example: scan with custom target framework
14+
node convert-nuget.js --tfm net48
15+
16+
# Example: scan from a specific directory
17+
node convert-nuget.js --root ./projects
18+
```
19+
20+
## Local Docker Usage
21+
22+
Pull the Docker image from GitHub Container Registry and run it locally:
23+
24+
```bash
25+
# Pull the latest image
26+
docker pull ghcr.io/semgrep/convert-nuget
27+
28+
# Run the conversion (scan from current directory)
29+
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/semgrep/convert-nuget
30+
31+
# Run the conversion (scan from a specific subdirectory)
32+
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/semgrep/convert-nuget --root /workspace/some/subdirectory
33+
34+
# Run with custom target framework
35+
docker run --rm -v $(pwd):/workspace -w /workspace ghcr.io/semgrep/convert-nuget --tfm net48
36+
```
37+
38+
## Docker CI Usage
39+
40+
```yaml
41+
# GitHub Actions example
42+
- name: Convert packages.config
43+
run: |
44+
docker run -v ${{ github.workspace }}:/workspace -w /workspace ghcr.io/semgrep/convert-nuget
45+
46+
# GitLab CI example
47+
convert-nuget:
48+
script:
49+
- docker run -v $PWD:/workspace -w /workspace ghcr.io/semgrep/convert-nuget
50+
```
51+
52+
```bash
53+
# Command line
54+
docker run -v $(pwd):/workspace -w /workspace ghcr.io/semgrep/convert-nuget
55+
```
56+
57+
## GitHub Actions Usage
58+
59+
To automatically update & check in any changes made to packages.config, use the below action
60+
61+
```yaml
62+
name: Convert packages.config to packages.lock.json
63+
on:
64+
push:
65+
paths:
66+
- '**/packages.config'
67+
68+
permissions:
69+
contents: write # needed to push commits
70+
71+
jobs:
72+
convert-nuget:
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Checkout repo
76+
uses: actions/checkout@v4
77+
with:
78+
fetch-depth: 0 # so we can push back to the same ref
79+
80+
- name: Convert packages.config
81+
run: |
82+
docker run -v "${{ github.workspace }}:/workspace" -w /workspace ghcr.io/semgrep/convert-nuget
83+
84+
- name: Commit updated lock files (if any)
85+
run: |
86+
set -euo pipefail
87+
88+
# make the workspace safe for git (sometimes needed in CI)
89+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
90+
91+
# author details for the commit
92+
git config user.name "github-actions[bot]"
93+
git config user.email "github-actions[bot]@users.noreply.github.com"
94+
95+
# stage only lock files that changed/appeared
96+
CHANGED=$(git status --porcelain -- '**/packages.lock.json' | wc -l)
97+
if [ "$CHANGED" -gt 0 ]; then
98+
git add **/packages.lock.json
99+
git commit -m "chore(convert-nuget): update lock files after packages.config change"
100+
git push
101+
echo "Committed and pushed lock file updates."
102+
else
103+
echo "No lock file changes to commit."
104+
fi
105+
```
106+
107+
## Options
108+
109+
- `--tfm <TFM>`: Target framework moniker (default: `net472`)
110+
- `--root <DIR>`: Root directory to search (default: current working directory)
111+
- `-h, --help`: Show help message

0 commit comments

Comments
 (0)