Skip to content

Bump actions/upload-artifact from 4 to 6 #3

Bump actions/upload-artifact from 4 to 6

Bump actions/upload-artifact from 4 to 6 #3

name: Prevent engineering system changes in PRs
on: pull_request
permissions: {}
jobs:
main:
name: Prevent engineering system changes in PRs
runs-on: windows-latest
steps:
- name: Get file changes
uses: trilom/file-changes-action@a6ca26c14274c33b15e6499323aac178af06ad4b # v1.2.4
id: file_changes
- name: Check if engineering systems were modified
id: engineering_systems_check
shell: pwsh
run: |
$filesPath = "$env:USERPROFILE\files.json"
if (!(Test-Path $filesPath)) {
Write-Error "files.json not found"
exit 1
}
$json = Get-Content $filesPath -Raw | ConvertFrom-Json
$patterns = @(
'^\.github/workflows/',
'^build/',
'^package\.json$'
)
$modified = $false
foreach ($file in $json) {
foreach ($pattern in $patterns) {
if ($file -match $pattern) {
$modified = $true
break
}
}
if ($modified) { break }
}
if ($modified) {
"engineering_systems_modified=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "Engineering systems were modified in this PR"
} else {
"engineering_systems_modified=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "No engineering systems were modified in this PR"
}
- name: Prevent Copilot from modifying engineering systems
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && github.event.pull_request.user.login == 'Copilot' }}
shell: pwsh
run: |
Write-Host "Copilot is not allowed to modify .github/workflows, build folder files, or package.json files."
Write-Host "If you need to update engineering systems, please do so manually or through authorized means."
exit 1
- uses: octokit/request-action@dad4362715b7fb2ddedf9772c8670824af564f0d # v2.4.0
id: get_permissions
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && github.event.pull_request.user.login != 'Copilot' }}
with:
route: GET /repos/microsoft/vscode/collaborators/${{ github.event.pull_request.user.login }}/permission
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set control output variable
id: control
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && github.event.pull_request.user.login != 'Copilot' }}
shell: pwsh
run: |
$permission = (ConvertFrom-Json '${{ steps.get_permissions.outputs.data }}').permission
$user = "${{ github.event.pull_request.user.login }}"
$isDependabot = $user -eq "dependabot[bot]"
$blockedRoles = @("admin", "maintain", "write")
$shouldRun = -not ($blockedRoles -contains $permission) -and (-not $isDependabot)
Write-Host "user: $user"
Write-Host "role: $permission"
Write-Host "is dependabot: $isDependabot"
Write-Host "should_run: $shouldRun"
"should_run=$shouldRun" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
- name: Check for engineering system changes
if: ${{ steps.engineering_systems_check.outputs.engineering_systems_modified == 'true' && steps.control.outputs.should_run == 'true' }}
shell: pwsh
run: |
Write-Host "Changes to .github/workflows/, build/ folder files, or package.json files aren't allowed in PRs."
exit 1