Skip to content

update-json

update-json #2919

Workflow file for this run

name: update-json
# Environment variables
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Controls when the action will run.
on:
workflow_dispatch:
schedule:
- cron: "5 */12 * * *"
jobs:
update-pwsh:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen", "DnsClient-PS" -Force
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
# Run Pester tests
- name: Update app JSON
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
. "${{ github.workspace }}/scripts/Update-Json.ps1" -Path "${{ github.workspace }}/json"
- name: Save updated files list
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$UpdateFile = "${{ github.workspace }}/json/_update-pwsh.txt"
if (Test-Path -Path $UpdateFile) {
$Updates = Get-Content -Path $UpdateFile
}
$files = foreach ($item in (git status --short --porcelain)) { ([RegEx]::Match($item, "^..\s(.*)$")).Groups[1].Value }
if ($null -ne $files) {
$Updates += $files
$Updates | Select-Object -Unique | Out-File -FilePath $UpdateFile -Encoding "Utf8" -Force -Verbose
}
- name: Save last update list
shell: pwsh
working-directory: ${{ github.workspace }}
run: |
$params = @{
UpdateFile = "${{ github.workspace }}/json/_update-pwsh.txt"
LastUpdateFile = "${{ github.workspace }}/json/_lastupdate.txt"
}
. "${{ github.workspace }}/scripts/Save-LastUpdate.ps1" @params
# Format the date number for the commit message
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update json ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."
# update-powershell:
# needs: update-pwsh
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v4
# with:
# ref: main
# # Run Pester tests
# - name: Git pull
# shell: powershell
# run: |
# git config --global core.safecrlf false
# git pull origin main
# - name: Install modules
# shell: powershell
# run: |
# Install-Module -Name "Evergreen" -Force
# # Import GPG key
# - name: Import GPG key
# id: import_gpg
# uses: crazy-max/ghaction-import-gpg@v6
# with:
# gpg_private_key: ${{ secrets.GPGKEY }}
# passphrase: ${{ secrets.GPGPASSPHRASE }}
# git_user_signingkey: true
# git_commit_gpgsign: true
# git_config_global: true
# git_tag_gpgsign: true
# git_push_gpgsign: false
# git_committer_name: ${{ secrets.COMMIT_NAME }}
# git_committer_email: ${{ secrets.COMMIT_EMAIL }}
# # Run Pester tests
# - name: Update app JSON
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# . "${{ github.workspace }}\scripts\Update-Json.ps1" -Path "${{ github.workspace }}\json"
# - name: Save updated files list
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# $UpdateFile = "${{ github.workspace }}\json\_update-powershell.txt"
# if (Test-Path -Path $UpdateFile) {
# $Updates = Get-Content -Path $UpdateFile
# }
# $files = foreach ($item in (git status --short --porcelain)) { ([RegEx]::Match($item, "^..\s(.*)$")).Groups[1].Value }
# if ($null -ne $files) {
# $Updates += $files
# $Updates | Select-Object -Unique | Out-File -FilePath $UpdateFile -Encoding "Utf8" -Force -Verbose
# }
# - name: Save last update list
# shell: powershell
# working-directory: ${{ github.workspace }}
# run: |
# $params = @{
# UpdateFile = "${{ github.workspace }}\json\_update-powershell.txt"
# LastUpdateFile = "${{ github.workspace }}\json\_lastupdate.txt"
# }
# . "${{ github.workspace }}\scripts\Save-LastUpdate.ps1" @params
# # Format the date number for the commit message
# - name: Get date
# id: get-date
# shell: powershell
# run: |
# $Date = Get-Date -Format "yyyy.MM.dd"
# echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
# - name: Commit changes
# id: commit
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# commit_message: "Update json ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
# commit_user_name: ${{ secrets.COMMIT_NAME }}
# commit_user_email: ${{ secrets.COMMIT_EMAIL }}
# - name: "Run if changes have been detected"
# if: steps.commit.outputs.changes_detected == 'true'
# run: echo "Changes committed."
# - name: "Run if no changes have been detected"
# if: steps.commit.outputs.changes_detected == 'false'
# run: echo "No changes detected."
update-kv-apps:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV with recent apps
id: update-apps
shell: pwsh
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
foreach ($UpdateFile in @("${{ github.workspace }}/json/_update-pwsh.txt", "${{ github.workspace }}/json/_update-powershell.txt")) {
$Files = Get-Content -Path $UpdateFile -ErrorAction "SilentlyContinue"
if ($null -ne $Files) {
Write-Host "Found $($Files.Count) files with changes."
foreach ($file in $Files) {
Write-Host "`nChecking: $file"
if ($file -match "json$") {
Write-Host "Update with: ${{ github.workspace }}/$file."
try {
$file = Get-Item -Path "${{ github.workspace }}/$file" -ErrorAction "SilentlyContinue"
wrangler kv:key put $file.BaseName.ToLower() --path=$($file.FullName) --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
}
catch {
Write-Warning -Message "Input from $file is not a valid."
}
}
}
}
}
- name: Remove update files
id: remove-update
shell: pwsh
run: |
$Files = "${{ github.workspace }}/json/_update-pwsh.txt", "${{ github.workspace }}/json/_update-powershell.txt"
Remove-Item -Path $Files -Force -ErrorAction "SilentlyContinue"
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen" -Force
- name: Update Cloudflare KV with all apps list
id: update-allapps
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
try {
Import-Module -Name "Evergreen" -Force
Find-EvergreenApp | ConvertTo-Json | Out-File -FilePath "./AllApps.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "_allapps" --path="./AllApps.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
}
catch { $_.Exception.Message }
finally { Remove-Item -Path "./AllApps.json" -Force -ErrorAction "SilentlyContinue" }
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update KV ${{ steps.get-date.outputs.date }}.${{ github.run_number }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."
update-endpoints-versions:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
repository: 'aaronparker/evergreen'
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV for endpoints/versions data
id: update-endpoints
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
# Get endpoint URLs from Evergreen manifests and post to the version endpoint
$UrlMatch = "http[s]?\:\/\/([^\/?#]+)(?:[\/?#]|$)"
$Endpoints = Get-ChildItem -Path "${{ github.workspace }}/Evergreen/Manifests" -Recurse -Include "*.json" | ForEach-Object {
Write-Host "Processing: $($_.FullName)"
[PSCustomObject]@{
Application = $_.BaseName
Endpoints = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | `
Select-Object -Unique | `
Sort-Object) -replace "http://|https://", "").TrimEnd("/|#|`",|`"")))
Ports = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | Select-Object -Unique))) | ForEach-Object {
if ($_ -match "http://") { "80" }
if ($_ -match "https://") { "443" }
} | Select-Object -Unique | Sort-Object -Descending)
}
}
$Endpoints | ConvertTo-Json | Out-File -FilePath "${{ github.workspace }}/Endpoints.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "endpoints-versions" --path="${{ github.workspace }}/Endpoints.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"
update-endpoints-downloads:
needs: [update-pwsh]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: Install Wrangler
id: install-wrangler
shell: bash
run: |
npm install -g wrangler
- name: Update Cloudflare KV for endpoints/downloads data
id: update-endpoints
shell: pwsh
working-directory: "${{ github.workspace }}"
env:
CLOUDFLARE_ACCOUNT_ID: ${{secrets.CLOUDFLARE_ACCOUNT_ID}}
CLOUDFLARE_ZONE_ID: ${{secrets.CLOUDFLARE_ZONE_ID}}
CLOUDFLARE_API_TOKEN: ${{secrets.CLOUDFLARE_API_TOKEN}}
run: |
# Get endpoint URLs from Evergreen manifests and post to the downloads endpoint
$UrlMatch = "http[s]?\:\/\/([^\/?#]+)(?:[\/?#]|$)"
$Endpoints = Get-ChildItem -Path "${{ github.workspace }}/json" -Recurse -Include "*.json" | ForEach-Object {
Write-Host "Processing: $($_.FullName)"
[PSCustomObject]@{
Application = $_.BaseName
Endpoints = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | `
Select-Object -Unique | `
Sort-Object) -replace "http://|https://", "").TrimEnd("/|#|`",|`"")))
Ports = @(((((Select-String -Path $_.FullName -Pattern $UrlMatch).Matches.Value | Select-Object -Unique))) | ForEach-Object {
if ($_ -match "http://") { "80" }
if ($_ -match "https://") { "443" }
} | Select-Object -Unique | Sort-Object -Descending)
}
}
$Endpoints | ConvertTo-Json | Out-File -FilePath "${{ github.workspace }}/Endpoints.json" -Encoding "Utf8" -NoNewline
wrangler kv:key put "endpoints-downloads" --path="${{ github.workspace }}/Endpoints.json" --namespace-id="${{secrets.KV_PROD_NAMESPACE_ID}}"
Remove-Item -Path "${{ github.workspace }}/Endpoints.json"
update-docs:
needs: [update-pwsh, update-kv-apps]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.PAT }}
- name: Git pull
shell: pwsh
run: |
git config --global core.safecrlf false
git pull origin main
- name: Install modules
shell: pwsh
run: |
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
Install-Module -Name "Evergreen", "MarkdownPS" -Force
- name: Generate report
shell: pwsh
run: |
$params = @{
JsonPath = "${{ github.workspace }}/json"
OutputPath = "${{ github.workspace }}/docs/_apps"
IndexFile = "${{ github.workspace }}/docs/index.md"
LastUpdateFile = "${{ github.workspace }}/json/_lastupdate.txt"
}
. "${{ github.workspace }}/scripts/New-Report.ps1" @params
# Format the date number for the commit message
- name: Get date
id: get-date
shell: pwsh
run: |
$Date = Get-Date -Format "yyyy.MM.dd"
echo "date=$Date" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update docs ${{ steps.get-date.outputs.date }}.${{ github.run_number }} ${{ github.job }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Run if changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "Run if no changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."