Skip to content

Commit b558df2

Browse files
Merge pull request actions#209 from MaksimZhukov/introduce-reusable-workflows
Update workflows to use reusable ones
2 parents 6dd0b75 + 9feffed commit b558df2

File tree

6 files changed

+35
-168
lines changed

6 files changed

+35
-168
lines changed

.github/workflows/python-builder.yml renamed to .github/workflows/build-python-packages.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
name: Build python package
2-
1+
name: Build Python package
2+
run-name: Generate Python ${{ inputs.VERSION || '3.11.0' }}
33
on:
44
workflow_dispatch:
55
inputs:
66
VERSION:
77
description: 'Python version to build and upload'
8-
default: '3.9.9'
8+
default: '3.11.0'
99
required: true
1010
PUBLISH_RELEASES:
1111
description: 'Whether to publish releases'
1212
required: true
13-
default: 'false'
13+
type: boolean
14+
default: false
1415
PLATFORMS:
1516
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
1617
required: true
@@ -24,7 +25,7 @@ on:
2425
- 'main'
2526

2627
env:
27-
VERSION: ${{ github.event.inputs.VERSION || '3.9.9' }}
28+
VERSION: ${{ inputs.VERSION || '3.11.0' }}
2829
defaults:
2930
run:
3031
shell: pwsh
@@ -38,7 +39,7 @@ jobs:
3839
- name: Generate execution matrix
3940
id: generate-matrix
4041
run: |
41-
[String[]]$configurations = "${{ github.event.inputs.platforms || 'ubuntu-18.04,ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim()
42+
[String[]]$configurations = "${{ inputs.platforms || 'ubuntu-18.04,ubuntu-20.04,ubuntu-22.04,macos-11,windows-2019_x64,windows-2019_x86' }}".Split(",").Trim()
4243
$matrix = @()
4344
4445
foreach ($configuration in $configurations) {
@@ -66,7 +67,7 @@ jobs:
6667
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
6768
runs-on: ${{ matrix.os }}
6869
env:
69-
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }}
70+
ARTIFACT_NAME: python-${{ inputs.VERSION || '3.11.0' }}-${{ matrix.platform }}-${{ matrix.arch }}
7071
steps:
7172

7273
- name: Check out repository code
@@ -93,7 +94,7 @@ jobs:
9394
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
9495
runs-on: ${{ matrix.os }}
9596
env:
96-
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }}
97+
ARTIFACT_NAME: python-${{ inputs.VERSION || '3.11.0' }}-${{ matrix.platform }}-${{ matrix.arch }}
9798
steps:
9899

99100
- name: Check out repository code
@@ -164,7 +165,7 @@ jobs:
164165

165166
publish_release:
166167
name: Publish release
167-
if: github.event_name == 'workflow_dispatch' && github.event.inputs.PUBLISH_RELEASES == 'true'
168+
if: github.event_name == 'workflow_dispatch' && inputs.PUBLISH_RELEASES
168169
needs: test_python
169170
runs-on: ubuntu-latest
170171
steps:
@@ -207,7 +208,7 @@ jobs:
207208
- name: Trigger "Create Pull Request" workflow
208209
uses: actions/github-script@v6
209210
with:
210-
github-token: ${{ secrets.PERSONAL_TOKEN }}
211+
github-token: ${{ secrets.GITHUB_TOKEN }}
211212
script: |
212213
github.rest.actions.createWorkflowDispatch({
213214
owner: context.repo.owner,

.github/workflows/create-pr.yml

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,9 @@ name: Create Pull Request
22
on:
33
workflow_dispatch:
44

5-
defaults:
6-
run:
7-
shell: pwsh
8-
95
jobs:
10-
create_pr:
11-
name: Create Pull Request
12-
runs-on: ubuntu-latest
13-
steps:
14-
- uses: actions/checkout@v3
15-
with:
16-
submodules: true
17-
18-
- name: Create versions-manifest.json
19-
run: |
20-
./helpers/packages-generation/manifest-generator.ps1 -RepositoryFullName "$env:GITHUB_REPOSITORY" `
21-
-GitHubAccessToken "${{secrets.GITHUB_TOKEN}}" `
22-
-OutputFile "./versions-manifest.json" `
23-
-ConfigurationFile "./config/python-manifest-config.json"
24-
- name: Create GitHub PR
25-
run: |
26-
$formattedDate = Get-Date -Format "MM/dd/yyyy"
27-
./helpers/github/create-pull-request.ps1 `
28-
-RepositoryFullName "$env:GITHUB_REPOSITORY" `
29-
-AccessToken "${{secrets.GITHUB_TOKEN}}" `
30-
-BranchName "update-versions-manifest-file" `
31-
-CommitMessage "Update versions-manifest" `
32-
-PullRequestTitle "[versions-manifest] Update for release from ${formattedDate}" `
33-
-PullRequestBody "Update versions-manifest.json for release from ${formattedDate}"
6+
create-pr:
7+
uses: actions/versions-package-tools/.github/workflows/create-pr-to-update-manifest.yml@main
8+
with:
9+
tool-name: "python"
10+
secrets: inherit

.github/workflows/get-python-versions.yml

Lines changed: 6 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,93 +4,10 @@ on:
44
- cron: '0 3,15 * * *'
55
workflow_dispatch:
66

7-
env:
8-
TOOL_NAME: "Python"
9-
defaults:
10-
run:
11-
shell: pwsh
12-
137
jobs:
14-
find_new_versions:
15-
if: github.repository_owner == 'actions'
16-
name: Find new versions
17-
runs-on: ubuntu-latest
18-
outputs:
19-
versions_output: ${{ steps.Get_new_versions.outputs.TOOL_VERSIONS }}
20-
steps:
21-
- uses: actions/checkout@v3
22-
with:
23-
submodules: true
24-
25-
- id: Get_new_versions
26-
name: Get new versions
27-
run: ./helpers/get-new-tool-versions/get-new-tool-versions.ps1 -ToolName ${{ env.TOOL_NAME }}
28-
29-
check_new_versions:
30-
name: Check new versions
31-
runs-on: ubuntu-latest
32-
needs: find_new_versions
33-
env:
34-
TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}}
35-
steps:
36-
- uses: actions/checkout@v3
37-
with:
38-
submodules: true
39-
40-
- name: Check Versions
41-
if: env.TOOL_VERSIONS == ''
42-
run: |
43-
Write-Host "No new versions were found"
44-
Import-Module "./helpers/github/github-api.psm1"
45-
$gitHubApi = Get-GitHubApi -RepositoryFullName "$env:GITHUB_REPOSITORY" `
46-
-AccessToken "${{ secrets.PERSONAL_TOKEN }}"
47-
$gitHubApi.CancelWorkflow("$env:GITHUB_RUN_ID")
48-
Start-Sleep -Seconds 60
49-
- name: Send Slack notification
50-
run: |
51-
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
52-
$message = "The following versions of '${{ env.TOOL_NAME }}' are available to upload: ${{ env.TOOL_VERSIONS }}\nLink to the pipeline: $pipelineUrl"
53-
./helpers/get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
54-
-ToolName "${{ env.TOOL_NAME }}" `
55-
-ImageUrl "https://avatars.githubusercontent.com/u/1525981?s=200&v=4" `
56-
-Text "$message"
57-
58-
trigger_builds:
59-
name: Trigger builds
60-
runs-on: ubuntu-latest
61-
needs: [find_new_versions, check_new_versions]
62-
env:
63-
TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}}
64-
environment: Get Available Tools Versions - Publishing Approval
65-
steps:
66-
- uses: actions/checkout@v3
67-
with:
68-
submodules: true
69-
70-
- name: Trigger "Build python packages" workflow
71-
run:
72-
./helpers/github/run-ci-builds.ps1 -RepositoryFullName "$env:GITHUB_REPOSITORY" `
73-
-AccessToken "${{ secrets.PERSONAL_TOKEN }}" `
74-
-WorkflowFileName "python-builder.yml" `
75-
-WorkflowDispatchRef "main" `
76-
-ToolVersions "${{ env.TOOL_VERSIONS }}" `
77-
-PublishReleases "true"
78-
79-
check_build:
80-
name: Check build for failures
81-
runs-on: ubuntu-latest
82-
needs: [find_new_versions, check_new_versions, trigger_builds]
83-
if: failure()
84-
steps:
85-
- uses: actions/checkout@v3
86-
with:
87-
submodules: true
88-
89-
- name: Send Slack notification if build fails
90-
run: |
91-
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
92-
$message = "The build of the '${{ env.TOOL_NAME }}' detection pipeline failed :progress-error:\nLink to the pipeline: $pipelineUrl"
93-
./helpers/get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
94-
-ToolName "${{ env.TOOL_NAME }}" `
95-
-Text "$message" `
96-
-ImageUrl "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"
8+
get-new-python-versions:
9+
uses: actions/versions-package-tools/.github/workflows/get-new-tool-versions.yml@main
10+
with:
11+
tool-name: "Python"
12+
image-url: "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"
13+
secrets: inherit

.github/workflows/python-versions-runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ jobs:
2828
$versions = ${{ github.event.inputs.versions }}
2929
./builders/python-versions-runner.ps1 -Versions $versions.Split(",") -PublishRelease ${{ github.event.inputs.publish-releases }}
3030
env:
31-
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
31+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,21 @@
11
name: Validate manifest
2-
32
on:
3+
# The GITHUB_TOKEN secret is used to create a PR
4+
# The pull_request event will not be triggered by it
5+
# That's one of the reasons we need the schedule to validate the versions-manifest.json file
46
schedule:
57
- cron: '0 8,20 * * *'
6-
8+
workflow_dispatch:
79
pull_request:
810
branches:
911
- main
1012
paths:
1113
- 'versions-manifest.json'
1214

13-
env:
14-
TOOL_NAME: "Python"
15-
16-
defaults:
17-
run:
18-
shell: pwsh
19-
2015
jobs:
21-
validation:
22-
if: github.repository_owner == 'actions'
23-
runs-on: ubuntu-latest
24-
steps:
25-
- uses: actions/checkout@v3
26-
with:
27-
submodules: true
28-
29-
- name: Validate python-versions manifest
30-
run: .\helpers\packages-generation\manifest-validator.ps1 -ManifestPath '.\versions-manifest.json'
31-
32-
check_build:
33-
name: Check validation for failures
34-
runs-on: ubuntu-latest
35-
needs: [validation]
36-
if: failure()
37-
steps:
38-
- uses: actions/checkout@v3
39-
with:
40-
submodules: true
41-
42-
- name: Send Slack notification if validation fails
43-
run: |
44-
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
45-
$message = "The validation of python-versions manifest failed. \nLink to the pipeline: $pipelineUrl"
46-
.\helpers\get-new-tool-versions\send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
47-
-ToolName "${{ env.TOOL_NAME }}" `
48-
-Text "$message" `
49-
-ImageUrl "https://www.python.org/static/community_logos/python-powered-h-100x130.png"
16+
manifest:
17+
uses: actions/versions-package-tools/.github/workflows/validate-manifest.yml@main
18+
with:
19+
tool-name: "Python"
20+
image-url: "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"
21+
secrets: inherit

builders/invoke-workflow.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ function Invoke-Workflow {
1212
}
1313
} | ConvertTo-Json
1414
$headers = @{
15-
Authorization="Bearer $env:PERSONAL_TOKEN"
15+
Authorization="Bearer $env:TOKEN"
1616
}
1717
$actionsRepoUri = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions"
18-
Invoke-RestMethod -uri "$actionsRepoUri/workflows/python-builder.yml/dispatches" -method POST -headers $headers -body $payload
18+
Invoke-RestMethod -uri "$actionsRepoUri/workflows/build-python-packages.yml/dispatches" -method POST -headers $headers -body $payload
1919

2020
$result = [PSCustomObject]@{
2121
Version = $Version

0 commit comments

Comments
 (0)