Skip to content

Commit

Permalink
chore: enhance the publishing to other repositories then github (#1028)
Browse files Browse the repository at this point in the history
#### What this PR does / why we need it

Publishing to external repositories might fail for various reasons,
therefore we should be able to easily trigger the publishing to those
repositories again and again without the need to rebuild a new release
from scratch.
  • Loading branch information
hilmarf authored Nov 5, 2024
1 parent 1a0570e commit f2f7b76
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 50 deletions.
56 changes: 9 additions & 47 deletions .github/workflows/publish-to-other-than-github.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,18 @@
name: Publish Release to other package registries than Github

on:
workflow_dispatch:
inputs:
version:
type: string
description: 'Version of the latest release (e.g. v0.42.0)'
required: false
default: ''
repository_dispatch:
types: [ocm-cli-release]
types: [publish-ocm-cli]

jobs:

push-to-aur:
name: Update Arch Linux User Repository
if: github.event.client_payload.push-to-aur && github.event.client_payload.version != ''
runs-on: ubuntu-latest
steps:
- name: Ensure proper version
run: |
if [ -n "${{ github.event.inputs.version }}" ]; then
echo "RELEASE_VERSION=$(echo ${{ github.event.inputs.version }} | tr -d ['v'])" >> $GITHUB_ENV
exit 0
fi
if [ -n "${{ github.event.client_payload.version }}" ]; then
echo "RELEASE_VERSION=$(echo ${{ github.event.client_payload.version }} | tr -d ['v'])" >> $GITHUB_ENV
exit 0
fi
echo "Version not provided"
exit 1
run: echo "RELEASE_VERSION=$(echo ${{ github.event.client_payload.version }} | tr -d ['v'])" >> $GITHUB_ENV
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
Expand All @@ -56,24 +40,13 @@ jobs:
push-to-chocolatey:
name: Update Chocolatey
if: github.event.client_payload.push-to-chocolatey && github.event.client_payload.version != ''
runs-on: windows-latest
steps:
- name: Ensure proper version
run: |
$workflow_version = "${{ github.event.inputs.version }}"
$repository_version = "${{ github.event.client_payload.version }}"
if (-not ([string]::IsNullOrEmpty($workflow_version))) {
$workflow_version = "$workflow_version" -replace 'v'
echo "RELEASE_VERSION=$workflow_version" | Out-File $env:GITHUB_ENV
exit 0
}
if (-not ([string]::IsNullOrEmpty($repository_version))) {
$repository_version = "$repository_version" -replace 'v'
echo "RELEASE_VERSION=($repository_version -replace 'v')" | Out-File $env:GITHUB_ENV
exit 0
}
Write-Host "Version not provided"
exit 1
$version = "${{ github.event.client_payload.version }}" -replace 'v'
echo "RELEASE_VERSION=$version" | Out-File $env:GITHUB_ENV
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
Expand All @@ -91,24 +64,13 @@ jobs:
push-to-winget:
name: Update Winget
if: github.event.client_payload.push-to-winget && github.event.client_payload.version != ''
runs-on: windows-latest
steps:
- name: Ensure proper version
run: |
$workflow_version = "${{ github.event.inputs.version }}"
$repository_version = "${{ github.event.client_payload.version }}"
if (-not ([string]::IsNullOrEmpty($workflow_version))) {
$workflow_version = "$workflow_version" -replace 'v'
echo "RELEASE_VERSION=$workflow_version" | Out-File $env:GITHUB_ENV
exit 0
}
if (-not ([string]::IsNullOrEmpty($repository_version))) {
$repository_version = "$repository_version" -replace 'v'
echo "RELEASE_VERSION=$repository_version" | Out-File $env:GITHUB_ENV
exit 0
}
Write-Host "Version not provided"
exit 1
$version = "${{ github.event.client_payload.version }}" -replace 'v'
echo "RELEASE_VERSION=$version" | Out-File $env:GITHUB_ENV
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,6 @@ jobs:
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: open-component-model/ocm
event-type: ocm-cli-release
client-payload: '{"version": "${{ env.RELEASE_VERSION }}"}'
repository: ${{ github.repository_owner }}/ocm
event-type: publish-ocm-cli
client-payload: '{"version":"${{ env.RELEASE_VERSION }}","push-to-aur":true,"push-to-chocolatey":true,"push-to-winget":true}'
60 changes: 60 additions & 0 deletions .github/workflows/retrigger-publish-to-other.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Manually retrigger the publishing of ocm-cli to other repositories

on:
workflow_dispatch:
inputs:
version:
type: string
description: Which version (e.g. v0.42.0) do you want to publish?
required: true
default: ''
push-to-aur:
type: boolean
description: Do you want to push to the Arch Linux User Repository?
required: false
default: false
push-to-chocolatey:
type: boolean
description: Do you want to push to Chocolatey?
required: false
default: false
push-to-winget:
type: boolean
description: Do you want to push to Winget?
required: false
default: false

jobs:
retrigger:
name: Create new "Release Publish Event"
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
packages: write
steps:
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.OCMBOT_APP_ID }}
private_key: ${{ secrets.OCMBOT_PRIV_KEY }}
- name: Ensure proper version
run: |
curl -sSL -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ${{ steps.generate_token.outputs.token }}" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/open-component-model/ocm/releases > releases.json
jq -r '.[] | .tag_name' releases.json | grep -v -E '.*-rc|latest' > versions.txt
if grep -Fxq '${{ github.event.inputs.version }}' versions.txt; then
echo "Version (${{ github.event.inputs.version }}) found!"
else
echo "Version (${{ github.event.inputs.version }}) not found! This are the availble ones:"
cat versions.txt
exit 1
fi
echo "RELEASE_VERSION=$(echo ${{ github.event.inputs.version }} )" >> $GITHUB_ENV
- name: Publish Event
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ steps.generate_token.outputs.token }}
repository: ${{ github.repository_owner }}/ocm
event-type: publish-ocm-cli
client-payload: '{"version":"${{ env.RELEASE_VERSION }}","push-to-aur":${{ github.event.inputs.push-to-aur }},"push-to-chocolatey":${{ github.event.inputs.push-to-chocolatey }},"push-to-winget":${{ github.event.inputs.push-to-winget }}}'

0 comments on commit f2f7b76

Please sign in to comment.