Skip to content

Commit

Permalink
[repo] Switch core-version-update workflow to use a dedicated bot acc…
Browse files Browse the repository at this point in the history
…ount (#1852)
  • Loading branch information
CodeBlanch authored Jun 3, 2024
1 parent 47b667a commit 36d4698
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 18 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/automation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Resolve automation settings

on:
workflow_call:
outputs:
enabled:
value: ${{ jobs.resolve-automation.outputs.enabled == 'true' }}
token-secret-name:
value: ${{ jobs.resolve-automation.outputs.token-secret-name }}
username:
value: ${{ vars.AUTOMATION_USERNAME }}
email:
value: ${{ vars.AUTOMATION_EMAIL }}
secrets:
OPENTELEMETRYBOT_GITHUB_TOKEN:
required: true

jobs:
resolve-automation:

runs-on: ubuntu-latest

outputs:
enabled: ${{ steps.evaluate.outputs.enabled }}
token-secret-name: ${{ steps.evaluate.outputs.token-secret-name }}

env:
OPENTELEMETRYBOT_GITHUB_TOKEN_EXISTS: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN != '' }}

steps:
- id: evaluate
run: |
echo "enabled=${{ env.OPENTELEMETRYBOT_GITHUB_TOKEN_EXISTS == 'true' }}" >> "$GITHUB_OUTPUT"
echo "token-secret-name=OPENTELEMETRYBOT_GITHUB_TOKEN" >> "$GITHUB_OUTPUT"
31 changes: 18 additions & 13 deletions .github/workflows/core-version-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@ on:
description: 'Release tag'
type: string

permissions:
contents: write
pull-requests: write

jobs:
automation:
uses: ./.github/workflows/automation.yml
secrets: inherit

core-version-update:
runs-on: ubuntu-latest

needs: automation

runs-on: windows-latest
if: needs.automation.outputs.enabled

env:
GH_TOKEN: ${{ secrets[needs.automation.outputs.token-secret-name] }}

steps:
- uses: actions/checkout@v4
with:
# Note: By default GitHub only fetches 1 commit. MinVer needs to find
# the version tag which is typically NOT on the first commit so we
# retrieve them all.
fetch-depth: 0

ref: ${{ github.event.repository.default_branch }}
token: ${{ secrets[needs.automation.outputs.token-secret-name] }}
- name: Setup dotnet
uses: actions/setup-dotnet@v4

Expand All @@ -34,6 +37,8 @@ jobs:
Import-Module .\build\scripts\post-release.psm1
CreateOpenTelemetryCoreLatestVersionUpdatePullRequest `
-tag '${{ inputs.tag }}'
env:
GH_TOKEN: ${{ github.token }}
-gitRepository '${{ github.repository }}' `
-tag '${{ inputs.tag }}' `
-targetBranch '${{ github.event.repository.default_branch }}' `
-gitUserName '${{ needs.automation.outputs.username }}' `
-gitUserEmail '${{ needs.automation.outputs.email }}'
17 changes: 12 additions & 5 deletions build/scripts/post-release.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ Export-ModuleMember -Function CreatePackageValidationBaselineVersionUpdatePullRe

function CreateOpenTelemetryCoreLatestVersionUpdatePullRequest {
param(
[Parameter(Mandatory=$true)][string]$gitRepository,
[Parameter(Mandatory=$true)][string]$tag,
[Parameter()][string]$gitUserName=$gitHubBotUserName,
[Parameter()][string]$gitUserEmail=$gitHubBotEmail,
[Parameter()][string]$targetBranch="main"
[Parameter()][string]$targetBranch="main",
[Parameter()][string]$gitUserName,
[Parameter()][string]$gitUserEmail
)

$match = [regex]::Match($tag, '^(.*?-)(.*)$')
Expand Down Expand Up @@ -257,8 +258,14 @@ function CreateOpenTelemetryCoreLatestVersionUpdatePullRequest {
}
}

git config user.name $gitUserName
git config user.email $gitUserEmail
if ([string]::IsNullOrEmpty($gitUserName) -eq $false)
{
git config user.name $gitUserName
}
if ([string]::IsNullOrEmpty($gitUserEmail) -eq $false)
{
git config user.email $gitUserEmail
}

git switch --create $branch origin/$targetBranch --no-track 2>&1 | % ToString
if ($LASTEXITCODE -gt 0)
Expand Down
1 change: 1 addition & 0 deletions opentelemetry-dotnet-contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
ProjectSection(SolutionItems) = preProject
.github\workflows\add-labels.yml = .github\workflows\add-labels.yml
.github\workflows\assign-reviewers.yml = .github\workflows\assign-reviewers.yml
.github\workflows\automation.yml = .github\workflows\automation.yml
.github\workflows\ci-Exporter.OneCollector-Integration.yml = .github\workflows\ci-Exporter.OneCollector-Integration.yml
.github\workflows\ci.yml = .github\workflows\ci.yml
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
Expand Down

0 comments on commit 36d4698

Please sign in to comment.