Skip to content

Commit 1863445

Browse files
committed
Sync .github/workflows directory with azure-sdk-tools repository
1 parent 1038a6f commit 1863445

File tree

3 files changed

+317
-0
lines changed

3 files changed

+317
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
name: GitHub Event Processor
2+
3+
on:
4+
issues:
5+
types: [edited, labeled, opened, reopened, unlabeled]
6+
# issue_comment is used for both issues and pull_requests
7+
# github.event.issue.pull_request will be non-null on pull request comments
8+
issue_comment:
9+
types: [created]
10+
# synchronize is the pull_request_target event when changes are pushed
11+
# pull request merged is the closed event with github.event.pull_request.merged = true
12+
pull_request_target:
13+
types: [closed, labeled, opened, reopened, review_requested, synchronize, unlabeled]
14+
15+
# This removes all unnecessary permissions, the ones needed will be set below.
16+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
17+
permissions: {}
18+
19+
jobs:
20+
# This event requires the Azure CLI to get the LABEL_SERVICE_API_KEY from the vault.
21+
# Because the azure/login step adds time costly pre/post Az CLI commands to any every job
22+
# it's used in, split this into its own job so only the event that needs the Az CLI pays
23+
# the cost.
24+
event-handler-with-azure:
25+
permissions:
26+
issues: write
27+
pull-requests: write
28+
# For OIDC auth
29+
id-token: write
30+
contents: read
31+
name: Handle ${{ github.event_name }} ${{ github.event.action }} event with azure login
32+
runs-on: ubuntu-latest
33+
if: ${{ github.event_name == 'issues' && github.event.action == 'opened' }}
34+
steps:
35+
- name: 'Az CLI login'
36+
uses: azure/login@v2
37+
with:
38+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
39+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
40+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
41+
42+
- name: 'Run Azure CLI commands'
43+
run: |
44+
LABEL_SERVICE_API_KEY=$(az keyvault secret show \
45+
--vault-name issue-labeler \
46+
-n issue-labeler-func-key \
47+
-o tsv \
48+
--query value)
49+
50+
echo "::add-mask::$LABEL_SERVICE_API_KEY"
51+
echo "LABEL_SERVICE_API_KEY=$LABEL_SERVICE_API_KEY" >> $GITHUB_ENV
52+
53+
# To run github-event-processor built from source, for testing purposes, uncomment everything
54+
# in between the Start/End-Build From Source comments and comment everything in between the
55+
# Start/End-Install comments
56+
# Start-Install
57+
- name: Install GitHub Event Processor
58+
run: >
59+
dotnet tool install
60+
Azure.Sdk.Tools.GitHubEventProcessor
61+
--version 1.0.0-dev.20240917.2
62+
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
63+
--global
64+
shell: bash
65+
# End-Install
66+
67+
# Testing checkout of sources from the Azure/azure-sdk-tools repository
68+
# The ref: is the SHA from the pull request in that repository or the
69+
# refs/pull/<PRNumber>/merge for the latest on any given PR. If the repository
70+
# is a fork eg. <User>/azure-sdk-tools then the repository down below will
71+
# need to point to that fork
72+
# Start-Build
73+
# - name: Checkout tools repo for GitHub Event Processor sources
74+
# uses: actions/checkout@v3
75+
# with:
76+
# repository: Azure/azure-sdk-tools
77+
# path: azure-sdk-tools
78+
# ref: <refs/pull/<PRNumber>/merge> or <sha>
79+
80+
# - name: Build and install GitHubEventProcessor from sources
81+
# run: |
82+
# dotnet pack
83+
# dotnet tool install --global --prerelease --add-source ../../../artifacts/packages/Debug Azure.Sdk.Tools.GitHubEventProcessor
84+
# shell: bash
85+
# working-directory: azure-sdk-tools/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor
86+
# End-Build
87+
88+
- name: Process Action Event
89+
run: |
90+
github-event-processor ${{ github.event_name }} ${{ github.event_path }}
91+
shell: bash
92+
env:
93+
# This is a temporary secret generated by github
94+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
LABEL_SERVICE_API_KEY: ${{ env.LABEL_SERVICE_API_KEY }}
97+
98+
- name: Archive github event data
99+
uses: actions/upload-artifact@v4
100+
if: always()
101+
with:
102+
name: event
103+
path: ${{ github.event_path }}
104+
105+
event-handler:
106+
permissions:
107+
issues: write
108+
pull-requests: write
109+
name: Handle ${{ github.event_name }} ${{ github.event.action }} event
110+
runs-on: ubuntu-latest
111+
if: ${{ github.event_name != 'issues' || github.event.action != 'opened' }}
112+
steps:
113+
# To run github-event-processor built from source, for testing purposes, uncomment everything
114+
# in between the Start/End-Build From Source comments and comment everything in between the
115+
# Start/End-Install comments
116+
# Start-Install
117+
- name: Install GitHub Event Processor
118+
run: >
119+
dotnet tool install
120+
Azure.Sdk.Tools.GitHubEventProcessor
121+
--version 1.0.0-dev.20240917.2
122+
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
123+
--global
124+
shell: bash
125+
# End-Install
126+
127+
# Testing checkout of sources from the Azure/azure-sdk-tools repository
128+
# The ref: is the SHA from the pull request in that repository or the
129+
# refs/pull/<PRNumber>/merge for the latest on any given PR. If the repository
130+
# is a fork eg. <User>/azure-sdk-tools then the repository down below will
131+
# need to point to that fork
132+
# Start-Build
133+
# - name: Checkout tools repo for GitHub Event Processor sources
134+
# uses: actions/checkout@v3
135+
# with:
136+
# repository: Azure/azure-sdk-tools
137+
# path: azure-sdk-tools
138+
# ref: <refs/pull/<PRNumber>/merge> or <sha>
139+
140+
# - name: Build and install GitHubEventProcessor from sources
141+
# run: |
142+
# dotnet pack
143+
# dotnet tool install --global --prerelease --add-source ../../../artifacts/packages/Debug Azure.Sdk.Tools.GitHubEventProcessor
144+
# shell: bash
145+
# working-directory: azure-sdk-tools/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor
146+
# End-Build
147+
148+
- name: Process Action Event
149+
run: |
150+
github-event-processor ${{ github.event_name }} ${{ github.event_path }}
151+
shell: bash
152+
env:
153+
# This is a temporary secret generated by github
154+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret
155+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
156+
157+
- name: Archive github event data
158+
uses: actions/upload-artifact@v4
159+
if: always()
160+
with:
161+
name: event
162+
path: ${{ github.event_path }}

.github/workflows/event.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# NOTE: currently azure-sdk-actions only hosts check enforcer code.
2+
# If further functionality is added, this name should be updated to reflect
3+
# the more generic behavior
4+
name: Check Enforcer
5+
6+
on:
7+
check_suite:
8+
types: [completed]
9+
issue_comment:
10+
types: [created]
11+
12+
permissions: {}
13+
14+
jobs:
15+
event-handler:
16+
permissions:
17+
statuses: write # to set status (azure/azure-sdk-actions)
18+
pull-requests: write # to read pull requests and write comments (azure/azure-sdk-actions)
19+
checks: read # to read check status (azure/azure-sdk-actions)
20+
name: Handle ${{ github.event_name }} ${{ github.event.action }} event
21+
runs-on: ubuntu-latest # This image is intentionally set to "latest", and not to a specific version
22+
steps:
23+
- uses: azure/azure-sdk-actions@main
24+
with:
25+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: GitHub Scheduled Event Processor
2+
3+
on:
4+
schedule:
5+
# These are generated/confirmed using https://crontab.cronhub.io/
6+
# Close stale issues, runs every day at 1am - CloseStaleIssues
7+
- cron: '0 1 * * *'
8+
# Identify stale pull requests, every Friday at 5am - IdentifyStalePullRequests
9+
- cron: '0 5 * * FRI'
10+
# Close stale pull requests, every 6 hours at 02:30 AM, 08:30 AM, 02:30 PM and 08:30 PM - CloseStalePullRequests
11+
- cron: '30 2,8,14,20 * * *'
12+
# Identify stale issues, every 6 hours at 03:30 AM, 09:30 AM, 03:30 PM and 09:30 PM - IdentifyStaleIssues
13+
- cron: '30 3,9,15,21 * * *'
14+
# Close addressed issues, every 6 hours at 04:30 AM, 10:30 AM, 04:30 PM and 10:30 PM - CloseAddressedIssues
15+
- cron: '30 4,10,16,22 * * *'
16+
# Lock closed issues, every 6 hours at 05:30 AM, 11:30 AM, 05:30 PM and 11:30 PM - LockClosedIssues
17+
- cron: '30 5,11,17,23 * * *'
18+
# Enforce max life of issues, every M,W,F at 10:00 AM PST - EnforceMaxLifeOfIssues
19+
# Note: GitHub uses UTC, to run at 10am PST, the cron task needs to be 6pm (1800 hours) UTC
20+
# When scheduling for multiple days the numeric days 0-6 (0=Sunday) must be used.
21+
- cron: '0 18 * * 1,3,5'
22+
# This removes all unnecessary permissions, the ones needed will be set below.
23+
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
24+
permissions: {}
25+
26+
jobs:
27+
event-handler:
28+
permissions:
29+
issues: write
30+
pull-requests: write
31+
name: Handle ${{ github.event.schedule }} ${{ github.event.action }} event
32+
runs-on: ubuntu-latest
33+
steps:
34+
# To run github-event-processor built from source, for testing purposes, uncomment everything
35+
# in between the Start/End-Build From Source comments and comment everything in between the
36+
# Start/End-Install comments
37+
# Start-Install
38+
- name: Install GitHub Event Processor
39+
run: >
40+
dotnet tool install
41+
Azure.Sdk.Tools.GitHubEventProcessor
42+
--version 1.0.0-dev.20240917.2
43+
--add-source https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json
44+
--global
45+
shell: bash
46+
# End-Install
47+
48+
# Testing checkout of sources from the Azure/azure-sdk-tools repository
49+
# The ref: is the SHA from the pull request in that repository or the
50+
# refs/pull/<PRNumber>/merge for the latest on any given PR. If the repository
51+
# is a fork eg. <User>/azure-sdk-tools then the repository down below will
52+
# need to point to that fork
53+
# Start-Build
54+
# - name: Checkout tools repo for GitHub Event Processor sources
55+
# uses: actions/checkout@v3
56+
# with:
57+
# repository: Azure/azure-sdk-tools
58+
# path: azure-sdk-tools
59+
# ref: <refs/pull/<PRNumber>/merge> or <sha>
60+
61+
# - name: Build and install GitHubEventProcessor from sources
62+
# run: |
63+
# dotnet pack
64+
# dotnet tool install --global --prerelease --add-source ../../../artifacts/packages/Debug Azure.Sdk.Tools.GitHubEventProcessor
65+
# shell: bash
66+
# working-directory: azure-sdk-tools/tools/github-event-processor/Azure.Sdk.Tools.GitHubEventProcessor
67+
# End-Build
68+
69+
- name: Close Stale Issues Scheduled Event
70+
if: github.event.schedule == '0 1 * * *'
71+
run: |
72+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} CloseStaleIssues
73+
shell: bash
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76+
77+
- name: Identify Stale PullRequests Scheduled Event
78+
if: github.event.schedule == '0 5 * * FRI'
79+
run: |
80+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} IdentifyStalePullRequests
81+
shell: bash
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Close Stale PullRequests Scheduled Event
86+
if: github.event.schedule == '30 2,8,14,20 * * *'
87+
run: |
88+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} CloseStalePullRequests
89+
shell: bash
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
93+
- name: Identify Stale Issues Scheduled Event
94+
if: github.event.schedule == '30 3,9,15,21 * * *'
95+
run: |
96+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} IdentifyStaleIssues
97+
shell: bash
98+
env:
99+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
100+
101+
- name: Close Addressed Issues Scheduled Event
102+
if: github.event.schedule == '30 4,10,16,22 * * *'
103+
run: |
104+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} CloseAddressedIssues
105+
shell: bash
106+
env:
107+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
108+
109+
- name: Lock Closed Issues Scheduled Event
110+
if: github.event.schedule == '30 5,11,17,23 * * *'
111+
run: |
112+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} LockClosedIssues
113+
shell: bash
114+
env:
115+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
117+
- name: Enforce Max Life of Issues Scheduled Event
118+
if: github.event.schedule == '0 18 * * 1,3,5'
119+
run: |
120+
github-event-processor ${{ github.event_name }} ${{ github.event_path }} EnforceMaxLifeOfIssues
121+
shell: bash
122+
env:
123+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
125+
- name: Archive github event data
126+
uses: actions/upload-artifact@v4
127+
if: always()
128+
with:
129+
name: event
130+
path: ${{ github.event_path }}

0 commit comments

Comments
 (0)