Update workflows to use reusable ones

This commit is contained in:
MaksimZhukov 2022-12-05 21:45:47 +01:00
parent 08fcc9e2f9
commit 626f42cb96
6 changed files with 32 additions and 165 deletions

View File

@ -1,16 +1,17 @@
name: Build python package name: Build Python package
run-name: Generate Python ${{ inputs.VERSION || '3.11.0' }}
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
VERSION: VERSION:
description: 'Python version to build and upload' description: 'Python version to build and upload'
default: '3.9.9' default: '3.11.0'
required: true required: true
PUBLISH_RELEASES: PUBLISH_RELEASES:
description: 'Whether to publish releases' description: 'Whether to publish releases'
required: true required: true
default: 'false' type: boolean
default: false
PLATFORMS: PLATFORMS:
description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)' description: 'Platforms for execution in "os" or "os_arch" format (arch is "x64" by default)'
required: true required: true
@ -24,7 +25,7 @@ on:
- 'main' - 'main'
env: env:
VERSION: ${{ github.event.inputs.VERSION || '3.9.9' }} VERSION: ${{ inputs.VERSION || '3.11.0' }}
defaults: defaults:
run: run:
shell: pwsh shell: pwsh
@ -66,7 +67,7 @@ jobs:
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }} include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }} ARTIFACT_NAME: python-${{ inputs.VERSION || '3.11.0' }}-${{ matrix.platform }}-${{ matrix.arch }}
steps: steps:
- name: Check out repository code - name: Check out repository code
@ -93,7 +94,7 @@ jobs:
include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }} include: ${{ fromJson(needs.generate_matrix.outputs.matrix) }}
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
ARTIFACT_NAME: python-${{ github.event.inputs.VERSION || '3.9.9' }}-${{ matrix.platform }}-${{ matrix.arch }} ARTIFACT_NAME: python-${{ inputs.VERSION || '3.11.0' }}-${{ matrix.platform }}-${{ matrix.arch }}
steps: steps:
- name: Check out repository code - name: Check out repository code
@ -207,7 +208,7 @@ jobs:
- name: Trigger "Create Pull Request" workflow - name: Trigger "Create Pull Request" workflow
uses: actions/github-script@v6 uses: actions/github-script@v6
with: with:
github-token: ${{ secrets.PERSONAL_TOKEN }} github-token: ${{ secrets.GITHUB_TOKEN }}
script: | script: |
github.rest.actions.createWorkflowDispatch({ github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner, owner: context.repo.owner,

View File

@ -2,32 +2,9 @@ name: Create Pull Request
on: on:
workflow_dispatch: workflow_dispatch:
defaults:
run:
shell: pwsh
jobs: jobs:
create_pr: create-pr:
name: Create Pull Request uses: actions/versions-package-tools/.github/workflows/create-pr-to-update-manifest.yml@main
runs-on: ubuntu-latest with:
steps: tool-name: "python"
- uses: actions/checkout@v3 secrets: inherit
with:
submodules: true
- name: Create versions-manifest.json
run: |
./helpers/packages-generation/manifest-generator.ps1 -RepositoryFullName "$env:GITHUB_REPOSITORY" `
-GitHubAccessToken "${{secrets.GITHUB_TOKEN}}" `
-OutputFile "./versions-manifest.json" `
-ConfigurationFile "./config/python-manifest-config.json"
- name: Create GitHub PR
run: |
$formattedDate = Get-Date -Format "MM/dd/yyyy"
./helpers/github/create-pull-request.ps1 `
-RepositoryFullName "$env:GITHUB_REPOSITORY" `
-AccessToken "${{secrets.GITHUB_TOKEN}}" `
-BranchName "update-versions-manifest-file" `
-CommitMessage "Update versions-manifest" `
-PullRequestTitle "[versions-manifest] Update for release from ${formattedDate}" `
-PullRequestBody "Update versions-manifest.json for release from ${formattedDate}"

View File

@ -4,93 +4,10 @@ on:
- cron: '0 3,15 * * *' - cron: '0 3,15 * * *'
workflow_dispatch: workflow_dispatch:
env:
TOOL_NAME: "Python"
defaults:
run:
shell: pwsh
jobs: jobs:
find_new_versions: get-new-python-versions:
if: github.repository_owner == 'actions' uses: actions/versions-package-tools/.github/workflows/get-new-tool-versions.yml@main
name: Find new versions with:
runs-on: ubuntu-latest tool-name: "Python"
outputs: image-url: "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"
versions_output: ${{ steps.Get_new_versions.outputs.TOOL_VERSIONS }} secrets: inherit
steps:
- uses: actions/checkout@v3
with:
submodules: true
- id: Get_new_versions
name: Get new versions
run: ./helpers/get-new-tool-versions/get-new-tool-versions.ps1 -ToolName ${{ env.TOOL_NAME }}
check_new_versions:
name: Check new versions
runs-on: ubuntu-latest
needs: find_new_versions
env:
TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}}
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Check Versions
if: env.TOOL_VERSIONS == ''
run: |
Write-Host "No new versions were found"
Import-Module "./helpers/github/github-api.psm1"
$gitHubApi = Get-GitHubApi -RepositoryFullName "$env:GITHUB_REPOSITORY" `
-AccessToken "${{ secrets.PERSONAL_TOKEN }}"
$gitHubApi.CancelWorkflow("$env:GITHUB_RUN_ID")
Start-Sleep -Seconds 60
- name: Send Slack notification
run: |
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
$message = "The following versions of '${{ env.TOOL_NAME }}' are available to upload: ${{ env.TOOL_VERSIONS }}\nLink to the pipeline: $pipelineUrl"
./helpers/get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
-ToolName "${{ env.TOOL_NAME }}" `
-ImageUrl "https://avatars.githubusercontent.com/u/1525981?s=200&v=4" `
-Text "$message"
trigger_builds:
name: Trigger builds
runs-on: ubuntu-latest
needs: [find_new_versions, check_new_versions]
env:
TOOL_VERSIONS: ${{needs.find_new_versions.outputs.versions_output}}
environment: Get Available Tools Versions - Publishing Approval
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Trigger "Build python packages" workflow
run:
./helpers/github/run-ci-builds.ps1 -RepositoryFullName "$env:GITHUB_REPOSITORY" `
-AccessToken "${{ secrets.PERSONAL_TOKEN }}" `
-WorkflowFileName "python-builder.yml" `
-WorkflowDispatchRef "main" `
-ToolVersions "${{ env.TOOL_VERSIONS }}" `
-PublishReleases "true"
check_build:
name: Check build for failures
runs-on: ubuntu-latest
needs: [find_new_versions, check_new_versions, trigger_builds]
if: failure()
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Send Slack notification if build fails
run: |
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
$message = "The build of the '${{ env.TOOL_NAME }}' detection pipeline failed :progress-error:\nLink to the pipeline: $pipelineUrl"
./helpers/get-new-tool-versions/send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
-ToolName "${{ env.TOOL_NAME }}" `
-Text "$message" `
-ImageUrl "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"

View File

@ -28,4 +28,4 @@ jobs:
$versions = ${{ github.event.inputs.versions }} $versions = ${{ github.event.inputs.versions }}
./builders/python-versions-runner.ps1 -Versions $versions.Split(",") -PublishRelease ${{ github.event.inputs.publish-releases }} ./builders/python-versions-runner.ps1 -Versions $versions.Split(",") -PublishRelease ${{ github.event.inputs.publish-releases }}
env: env:
PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -1,6 +1,8 @@
name: Validate manifest name: Validate manifest
on: on:
# The GITHUB_TOKEN secret is used to create a PR
# The pull_request event will not be triggered by it
# That's one of the reasons we need the schedule to validate the versions-manifest.json file
schedule: schedule:
- cron: '0 8,20 * * *' - cron: '0 8,20 * * *'
@ -10,40 +12,10 @@ on:
paths: paths:
- 'versions-manifest.json' - 'versions-manifest.json'
env:
TOOL_NAME: "Python"
defaults:
run:
shell: pwsh
jobs: jobs:
validation: manifest:
if: github.repository_owner == 'actions' uses: actions/versions-package-tools/.github/workflows/validate-manifest.yml@main
runs-on: ubuntu-latest with:
steps: tool-name: "Python"
- uses: actions/checkout@v3 image-url: "https://avatars.githubusercontent.com/u/1525981?s=200&v=4"
with: secrets: inherit
submodules: true
- name: Validate python-versions manifest
run: .\helpers\packages-generation\manifest-validator.ps1 -ManifestPath '.\versions-manifest.json'
check_build:
name: Check validation for failures
runs-on: ubuntu-latest
needs: [validation]
if: failure()
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Send Slack notification if validation fails
run: |
$pipelineUrl = "$env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/actions/runs/$env:GITHUB_RUN_ID"
$message = "The validation of python-versions manifest failed. \nLink to the pipeline: $pipelineUrl"
.\helpers\get-new-tool-versions\send-slack-notification.ps1 -Url "${{ secrets.SLACK_CHANNEL_URL }}" `
-ToolName "${{ env.TOOL_NAME }}" `
-Text "$message" `
-ImageUrl "https://www.python.org/static/community_logos/python-powered-h-100x130.png"

View File

@ -12,10 +12,10 @@ function Invoke-Workflow {
} }
} | ConvertTo-Json } | ConvertTo-Json
$headers = @{ $headers = @{
Authorization="Bearer $env:PERSONAL_TOKEN" Authorization="Bearer $env:TOKEN"
} }
$actionsRepoUri = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions" $actionsRepoUri = "$env:GITHUB_API_URL/repos/$env:GITHUB_REPOSITORY/actions"
Invoke-RestMethod -uri "$actionsRepoUri/workflows/python-builder.yml/dispatches" -method POST -headers $headers -body $payload Invoke-RestMethod -uri "$actionsRepoUri/workflows/build-python-packages.yml/dispatches" -method POST -headers $headers -body $payload
$result = [PSCustomObject]@{ $result = [PSCustomObject]@{
Version = $Version Version = $Version