Skip to content

Commit

Permalink
Checkout a separate repo instead of the submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Feb 13, 2024
1 parent ef907c7 commit 0a26f93
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 36 deletions.
36 changes: 9 additions & 27 deletions .github/workflows/update-npm-dependencies.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
$repoRoot = Resolve-Path -Path "$PSScriptRoot/../..";

# Update the .npmrc file to point to the cache location as a repo instead of a submodule
$npmrcPath = Join-Path -Path $repoRoot -ChildPath ".npmrc"
$content = Get-Content -Path $npmrcPath;
$content = $content -replace "cache=./src/submodules/Node-Externals/cache", "cache=../Node-Externals/cache";
$content | Set-Content -Path $npmrcPath;

Remove-Item -Path "package-lock.json" -Force -ErrorAction Stop
npm install
$diffResult = git diff-index HEAD -- ./package-lock.json
if ($null -eq $diffResult) {
# There are no changes so we don't need to do anything
Write-Host "No changes detected in package-lock.json"
} else {
# There are changes so we need to perform the following actions:
# Commit package-lock.json with the message "Update NPM dependencies".
# Get the current commit hash of the repository. We'll call it $CurrentCommitHash
# Navigate to src/submodules/Node-Externals (which is a submodule) that contains the npm-cache
# Commit the changes to the submodule with the message. Update offline NPM Cache (Get-Date -Format "yyyy-MM-dd") $CurrentCommitHash
# Go back to the root of the repository
# Add the submodule changes to the commit
# Commit the changes with the message "Update Node-Externals submodule"

git add package-lock.json
git commit -m "[Infrastructure] Update NPM dependencies"
$CurrentCommitHash = (git rev-parse HEAD).Trim()
Push-Location -Path (Join-Path $repoRoot -ChildPath "src/submodules/Node-Externals")
git add .
$commitMessage = @"
[Infrastructure] Update offline NPM Cache $(Get-Date -Format "yyyy-MM-dd")
https://github.com/dotnet/aspnetcore/commit/$CurrentCommitHash
"@;
git commit -m $commitMessage
Pop-Location
git add .
git commit -m "[Infrastructure] Update Node-Externals submodule"

# Notify the github workflow by setting the result output variable
Write-Output "changes=true" >> $GITHUB_OUTPUT
}

# Undo the changes to the .npmrc file
git checkout -- ./.npmrc
30 changes: 21 additions & 9 deletions .github/workflows/update-npm-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,57 @@ jobs:
runs-on: windows-latest

steps:
- name: Checkout repository
- name: Checkout aspnetcore repository
uses: actions/checkout@v2
with:
repository: 'dotnet/aspnetcore'
ref: 'main'
path: 'aspnetcore'

- name: Checkout submodule
run: git submodule update --init --recursive
- name: Checkout Node-Externals repository
uses: actions/checkout@v2
with:
repository: 'dotnet/Node-Externals'
ref: 'main'
path: 'node-externals'

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x

- name: Set up git user name and email
run: |
git config --global user.name "dotnet-maestro[bot]"
git config --global user.email "42748379+dotnet-maestro[bot]@users.noreply.github.com"
- name: Run script
shell: pwsh
id: update-npm-dependencies
run: ./.github/workflows/update-npm-dependencies.ps1

- name: Create PR to update the offline package cache
# if: steps.update-npm-dependencies.outputs.changes == 'true'
id: update-offline-package-cache
uses: dotnet/actions-create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
path: ./src/submodules/Node-Externals/
path: ./node-externals/
commit-message: 'Update the NPM offline cache'
title: '[Infrastructure] Update the NPM offline cache'
body: 'Updates the npm offline cache to match the associated package-lock.json file in dotnet/aspnetcore.'
labels: 'Type: Dependency Update :arrow_up_small:'
base: main
branch: github-action/update-npm-dependencies
branch-suffix: timestamp

- name: Update offline-cache submodule
shell: pwsh
run:
./.github/workflows/update-submodule-commit.ps1 ${{ steps.update-offline-package-cache.outputs.pull-request-head-sha }}

- name: Create PR to update package-lock.json and the offline package cache submodule
# if: steps.update-npm-dependencies.outputs.changes == 'true'
uses: dotnet/actions-create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'Update npm dependencies and offline cache submodule'
path: ./aspnetcore/
title: '[Infrastructure] Update npm dependencies'
body: 'Updates the package-lock.json file and the offline package cache submodule to match it.'
labels: 'Type: Dependency Update :arrow_up_small:'
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/update-npm-submodule-commit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Define a parameter to accept the commit sha
param(
[string]$CommitSha
)

# Fetch and checkout the commit sha in the submodule in src/submodules/Node-Externals
Set-Location src/submodules/Node-Externals
git fetch origin
git checkout $CommitSha

0 comments on commit 0a26f93

Please sign in to comment.