|
| 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