-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update MongoDB-Tools workflow and script
- Loading branch information
Showing
11 changed files
with
412 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: MongoDB.Compass PR | ||
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 3 0/4 * * * | ||
env: | ||
PackageName: MongoDB.Compass | ||
WebsiteURL: https://www.mongodb.com/try/download/tools | ||
|
||
jobs: | ||
winget: | ||
name: Publish winget package | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
path: Utesgui | ||
- name: Install winget | ||
uses: Cyberboss/install-winget@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Update package | ||
id: get_version | ||
working-directory: Utesgui | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.WINGET_PAT }} | ||
WINGET_PKGS_FORK_REPO: ${{ vars.WINGET_PKGS_FORK_REPO }} | ||
run: .\Scripts\Update-${{ env.PackageName }}.ps1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: MongoDB.Compass PR | ||
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 3 0/4 * * * | ||
env: | ||
PackageName: MongoDB.Compass | ||
WebsiteURL: https://www.mongodb.com/try/download/tools | ||
|
||
jobs: | ||
winget: | ||
name: Publish winget package | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
path: Utesgui | ||
- name: Install winget | ||
uses: Cyberboss/install-winget@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Update package | ||
id: get_version | ||
working-directory: Utesgui | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.WINGET_PAT }} | ||
WINGET_PKGS_FORK_REPO: ${{ vars.WINGET_PKGS_FORK_REPO }} | ||
run: .\Scripts\Update-${{ env.PackageName }}.ps1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: MongoDB.MongoDBAtlasCLI PR | ||
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 3 0/4 * * * | ||
env: | ||
PackageName: MongoDB.MongoDBAtlasCLI | ||
WebsiteURL: https://www.mongodb.com/try/download/tools | ||
PackageFilter: mongodb-atlas-cli | ||
|
||
jobs: | ||
winget: | ||
name: Publish winget package | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
path: Utesgui | ||
- name: Install winget | ||
uses: Cyberboss/install-winget@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Update package | ||
id: get_version | ||
working-directory: Utesgui | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.WINGET_PAT }} | ||
WINGET_PKGS_FORK_REPO: ${{ vars.WINGET_PKGS_FORK_REPO }} | ||
run: .\Scripts\Update-${{ env.PackageName }}.ps1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: MongoDB.MongoDBCLI PR | ||
# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: 3 0/4 * * * | ||
env: | ||
PackageName: MongoDB.MongoDBCLI | ||
WebsiteURL: https://www.mongodb.com/try/download/tools | ||
PackageFilter: mongocli | ||
|
||
jobs: | ||
winget: | ||
name: Publish winget package | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
path: Utesgui | ||
- name: Install winget | ||
uses: Cyberboss/install-winget@v1 | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Update package | ||
id: get_version | ||
working-directory: Utesgui | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.WINGET_PAT }} | ||
WINGET_PKGS_FORK_REPO: ${{ vars.WINGET_PKGS_FORK_REPO }} | ||
run: .\Scripts\Update-${{ env.PackageName }}.ps1 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
.github/workflows/MongoDB-Tools.yml → .github/workflows/MongoDB.Shell.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
if ($Env:GITHUB_TOKEN) { | ||
Write-Host 'GITHUB_TOKEN detected' | ||
$gitToken = ${Env:GITHUB_TOKEN} | ||
} | ||
else { | ||
Write-Host 'GITHUB_TOKEN not detected' | ||
exit 1 | ||
} | ||
|
||
$wingetPackage = ${Env:PackageName} | ||
$url = ${Env:WebsiteURL} | ||
|
||
# Placeholder for the release notes URL | ||
$releaseNotesUrl = "https://www.mongodb.com/docs/database-tools/release-notes/database-tools-changelog/#{version}-changelog" | ||
|
||
$PackageMapping = @{ | ||
"MongoDB.DatabaseTools" = "mongodb-database-tools" | ||
} | ||
|
||
Write-Host "Try to update MongoDB Tools" | ||
|
||
# Download the webpage | ||
$website = Invoke-WebRequest -Uri $url | ||
|
||
# Extract the content of the webpage | ||
$content = $website.Content | ||
|
||
# Find all strings that look like links and end with .msi | ||
$links = $content | Select-String -Pattern 'https?://[^"]+' -AllMatches | % { $_.Matches } | % { $_.Value } | ||
$msilinks = $links | Select-String -Pattern 'https?://[^\s]*\.msi' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | ||
|
||
foreach ($wingetPackage in $PackageMapping.Keys){ | ||
$PackageFilter = $PackageMapping[$wingetPackage] | ||
$Packagelinks = $msilinks | Select-String -Pattern "https?://[^\s]*$PackageFilter[^\s]*\.msi" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }| Where-Object { $_ -notmatch "$PackageFilter-isolated|$PackageFilter-readonly" } | ||
# Extract versions from the links | ||
$versions = $Packagelinks | ForEach-Object { $_ -match '(\d+\.\d+\.\d+(-rc\d*|-beta\d*)?)' | Out-Null; $matches[1] } | ||
|
||
# Exclude release candidates | ||
$stableVersions = $versions | Where-Object { $_ -notmatch '(-rc|beta)' } | ||
|
||
# Sort the versions and get the latest one | ||
$latestVersion = $stableVersions | Sort-Object {[Version]$_} | Select-Object -Last 1 | ||
$latestVersionUrl = $Packagelinks | Where-Object { $_ -match $latestVersion } | ||
Write-Host "Version found: $PackageFilter $latestVersion. URL: $latestVersionUrl" | ||
|
||
|
||
Write-Host "Version found: $latestVersion" | ||
|
||
$prMessage = "Update version: $wingetPackage version $latestVersion" | ||
$actualReleaseNotesUrl = $releaseNotesUrl -replace "{version}", $latestVersion | ||
|
||
$foundMessage, $textVersion, $separator, $wingetVersions = winget search --id $wingetPackage --source winget --versions | ||
|
||
# Check for existing versions in winget | ||
if ($wingetVersions -contains $latestVersion) { | ||
Write-Output "Latest version of $wingetPackage $latestVersion is already present in winget." | ||
} | ||
else { | ||
# Check for existing PRs | ||
Write-Host "Fetching existing PRs" | ||
#gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingOpenPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
#gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingMergedPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
|
||
$ExistingPRs = @($ExistingOpenPRs) + @($ExistingMergedPRs) | ||
|
||
# TODO Check if PR is already merged, if so exit | ||
|
||
# TODO if PR from us is already open, update PR with new version | ||
|
||
# TODO if PR is closed, not from us and no PR got merged, create new PR | ||
|
||
# TODO if PR is closed, from us and no PR got merged, throw error | ||
|
||
if ($ExistingPRs.Count -gt 0) { | ||
Write-Output "$foundMessage" | ||
$ExistingPRs | ForEach-Object { | ||
Write-Output "Found existing PR: $($_.title)" | ||
Write-Output "-> $($_.url)" | ||
} | ||
} | ||
elseif ($wingetVersions -and ($wingetVersions -notmatch $latestVersion)) { | ||
Write-Host "Open PR for update" | ||
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe | ||
.\wingetcreate.exe update $wingetPackage -s -v $latestVersion -u "$latestVersionUrl" --prtitle $prMessage -t $gitToken | ||
} | ||
else { | ||
Write-Output "$foundMessage" | ||
Write-Output "No existing PRs found. Check why wingetcreate has not run." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
if ($Env:GITHUB_TOKEN) { | ||
Write-Host 'GITHUB_TOKEN detected' | ||
$gitToken = ${Env:GITHUB_TOKEN} | ||
} | ||
else { | ||
Write-Host 'GITHUB_TOKEN not detected' | ||
exit 1 | ||
} | ||
|
||
#$wingetPackage = ${Env:PackageName} | ||
$url = ${Env:WebsiteURL} | ||
$PackageFilter = ${Env:PackageFilter} | ||
|
||
|
||
Write-Host "Try to update MongoDB Tools" | ||
|
||
# Download the webpage | ||
$website = Invoke-WebRequest -Uri $url | ||
|
||
# Extract the content of the webpage | ||
$content = $website.Content | ||
|
||
# Find all strings that look like links and end with .msi | ||
$links = $content | Select-String -Pattern 'https?://[^"]+' -AllMatches | % { $_.Matches } | % { $_.Value } | ||
$msilinks = $links | Select-String -Pattern 'https?://[^\s]*\.msi' -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value } | ||
|
||
foreach ($wingetPackage in $PackageMapping.Keys){ | ||
$PackageFilter = $PackageMapping[$wingetPackage] | ||
$Packagelinks = $msilinks | Select-String -Pattern "https?://[^\s]*$PackageFilter[^\s]*\.msi" -AllMatches | ForEach-Object { $_.Matches } | ForEach-Object { $_.Value }| Where-Object { $_ -notmatch "$PackageFilter-isolated|$PackageFilter-readonly" } | ||
# Extract versions from the links | ||
$versions = $Packagelinks | ForEach-Object { $_ -match '(\d+\.\d+\.\d+(-rc\d*|-beta\d*)?)' | Out-Null; $matches[1] } | ||
|
||
# Exclude release candidates | ||
$stableVersions = $versions | Where-Object { $_ -notmatch '(-rc|beta)' } | ||
|
||
# Sort the versions and get the latest one | ||
$latestVersion = $stableVersions | Sort-Object {[Version]$_} | Select-Object -Last 1 | ||
$latestVersionUrl = $Packagelinks | Where-Object { $_ -match $latestVersion } | ||
Write-Host "Version found: $PackageFilter $latestVersion. URL: $latestVersionUrl" | ||
|
||
|
||
Write-Host "Version found: $latestVersion" | ||
|
||
$prMessage = "Update version: $wingetPackage version $latestVersion" | ||
|
||
$foundMessage, $textVersion, $separator, $wingetVersions = winget search --id $wingetPackage --source winget --versions | ||
|
||
# Check for existing versions in winget | ||
if ($wingetVersions -contains $latestVersion) { | ||
Write-Output "Latest version of $wingetPackage $latestVersion is already present in winget." | ||
} | ||
else { | ||
# Check for existing PRs | ||
Write-Host "Fetching existing PRs" | ||
#gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingOpenPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'open' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
#gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
$ExistingMergedPRs = gh pr list --search "$($wingetPackage) $($latestVersion) in:title draft:false" --state 'merged' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json | ||
|
||
$ExistingPRs = @($ExistingOpenPRs) + @($ExistingMergedPRs) | ||
|
||
# TODO Check if PR is already merged, if so exit | ||
|
||
# TODO if PR from us is already open, update PR with new version | ||
|
||
# TODO if PR is closed, not from us and no PR got merged, create new PR | ||
|
||
# TODO if PR is closed, from us and no PR got merged, throw error | ||
|
||
if ($ExistingPRs.Count -gt 0) { | ||
Write-Output "$foundMessage" | ||
$ExistingPRs | ForEach-Object { | ||
Write-Output "Found existing PR: $($_.title)" | ||
Write-Output "-> $($_.url)" | ||
} | ||
} | ||
elseif ($wingetVersions -and ($wingetVersions -notmatch $latestVersion)) { | ||
Write-Host "Open PR for update" | ||
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe | ||
.\wingetcreate.exe update $wingetPackage -s -v $latestVersion -u "$latestVersionUrl" --prtitle $prMessage -t $gitToken | ||
} | ||
else { | ||
Write-Output "$foundMessage" | ||
Write-Output "No existing PRs found. Check why wingetcreate has not run." | ||
} | ||
} | ||
} |
Oops, something went wrong.