Skip to content

Commit

Permalink
refactor: support camunda generation release name
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed AbouZaid <6760103+aabouzaid@users.noreply.github.com>
  • Loading branch information
aabouzaid committed May 14, 2024
1 parent 079a43d commit d478e86
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 62 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/release-generation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: "Release - Generation"

on:
release:
types: [created]
tags:
# Example: 8.4+gen1
- 8\.\d+\+gen\d+
push:
branches:
- distro-255-aa-fix-release-workflow

env:
# Example: 8.4+gen1
CAMUNDA_RELEASE_NAME: 8.4+gen7

jobs:
release_script:
runs-on: ubuntu-latest
name: Build release notes
steps:
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "1.20"

- name: Build
working-directory: ./release-notes-fetcher
run: go build

- name: Generate token for Camunda GitHub org
id: generate-camunda-github-token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}

- name: Generate token for Camunda Cloud GitHub org
id: generate-camunda-cloud-github-token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
repository: camunda-cloud/identity

- name: Set vars
run: |
CAMUNDA_VERSION="$(echo ${CAMUNDA_RELEASE_NAME} | awk -F '+' '{print $1}')"
CONFIG_FILE="release-notes-fetcher/config/release-notes-fetcher-camunda-${CAMUNDA_VERSION}.yaml"
export GLOBAL_GITREF="$(yq '.gitRef.global' ${CONFIG_FILE})"
# Generate env var from git ref for all apps.
# This will generate env vars like "ZEEBE_GITREF".
yq '.gitRef | omit(["global"]) | keys' "${CONFIG_FILE}" | sed 's/- //g' |
while read APP_NAME; do
APP_REF="$(APP_NAME=${APP_NAME} yq '.gitRef.[env(APP_NAME)] // env(GLOBAL_GITREF)' ${CONFIG_FILE})"
echo "${APP_NAME^^}_GITREF=${APP_REF}" >> "${GITHUB_ENV}"
done
- name: Run release notes script
working-directory: ./release-notes-fetcher
run: set -o pipefail; ./release-notes-fetcher | tee release_notes.txt
env:
GITHUB_CAMUNDA_ACCESS_TOKEN: ${{ steps.generate-camunda-github-token.outputs.token }}
GITHUB_CAMUNDA_CLOUD_ACCESS_TOKEN: ${{ steps.generate-camunda-cloud-github-token.outputs.token }}

- name: Login to gh repo
working-directory: ./release-notes-fetcher
run: echo ${{ steps.generate-camunda-github-token.outputs.token }} | gh auth login --with-token

- name: Edit release notes with output from script
working-directory: ./release-notes-fetcher
run: gh release edit --notes-file release_notes.txt -R camunda/camunda-platform ${CAMUNDA_RELEASE_NAME}

- name: Create temporary directory for asset download/upload
working-directory: ./release-notes-fetcher
run: mkdir -p tmp

# Tasklist binaries are uploaded to zeebes repo
- name: Download Zeebe resources
working-directory: ./release-notes-fetcher/tmp
run: |
gh release download "${ZEEBE_GITREF}" \
-R camunda/zeebe \
-p "zbctl" \
-p "zbctl.sha1sum" \
-p "zbctl.exe" \
-p "zbctl.exe.sha1sum" \
-p "zbctl.darwin" \
-p "zbctl.darwin.sha1sum" \
-p "camunda-zeebe-${ZEEBE_GITREF}.tar.gz" \
-p "camunda-zeebe-${ZEEBE_GITREF}.tar.gz.sha1sum" \
-p "camunda-zeebe-${ZEEBE_GITREF}.zip" \
-p "camunda-zeebe-${ZEEBE_GITREF}.zip.sha1sum" \
-p "camunda-tasklist-${ZEEBE_GITREF}.zip" \
-p "camunda-tasklist-${ZEEBE_GITREF}.zip.sha1sum" \
-p "camunda-tasklist-${ZEEBE_GITREF}.tar.gz" \
-p "camunda-tasklist-${ZEEBE_GITREF}.tar.gz.sha1sum"
- name: Download Operate resources from monorepo
if: ${{ startsWith(env.CAMUNDA_RELEASE_NAME, '8.5') }}
working-directory: ./release-notes-fetcher/tmp
run: |
gh release download "operate-${OPERATE_GITREF}" \
-R camunda/zeebe \
-p "camunda-operate-${OPERATE_GITREF}.zip" \
-p "camunda-operate-${OPERATE_GITREF}.zip.sha1sum" \
-p "camunda-operate-${OPERATE_GITREF}.tar.gz" \
-p "camunda-operate-${OPERATE_GITREF}.tar.gz.sha1sum" \
- name: Download Operate resources
if: ${{ !startsWith(env.CAMUNDA_RELEASE_NAME, '8.5') }}
working-directory: ./release-notes-fetcher/tmp
run: |
gh release download "${OPERATE_GITREF}" \
-R camunda/operate \
-p "camunda-operate-${OPERATE_GITREF}.zip" \
-p "camunda-operate-${OPERATE_GITREF}.zip.sha1sum" \
-p "camunda-operate-${OPERATE_GITREF}.tar.gz" \
-p "camunda-operate-${OPERATE_GITREF}.tar.gz.sha1sum" \
- name: Login to Camunda Cloud
working-directory: ./release-notes-fetcher
run: echo ${{ steps.generate-camunda-cloud-github-token.outputs.token }} | gh auth login --with-token

- name: Download Identity resources
working-directory: ./release-notes-fetcher/tmp
run: |
gh release download "${IDENTITY_GITREF}" \
-R camunda-cloud/identity \
-p "camunda-identity-${IDENTITY_GITREF}.tar.gz" \
-p "camunda-identity-${IDENTITY_GITREF}.tar.gz.sha1sum" \
-p "camunda-identity-${IDENTITY_GITREF}.zip" \
-p "camunda-identity-${IDENTITY_GITREF}.zip.sha1sum"
- name: Login back to Camunda
working-directory: ./release-notes-fetcher
run: echo ${{ steps.generate-camunda-github-token.outputs.token }} | gh auth login --with-token

# - name: Upload resources
# working-directory: ./release-notes-fetcher/tmp
# run: gh release -R camunda/camunda-platform upload "${CAMUNDA_RELEASE_NAME}" *
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:

jobs:
release_script:
if: ! contains($GITHUB_REF_NAME, "+")
runs-on: ubuntu-latest
name: Build release script
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gitRef:
global: 8.4.7
operate: 8.4.8
identity:
tasklist:
zeebe:
66 changes: 56 additions & 10 deletions release-notes-fetcher/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package main

import (
"context"
"github.com/google/go-github/v54/github"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golang.org/x/oauth2"
"fmt"
"io"
"os"
"regexp"
"text/template"

"github.com/google/go-github/v54/github"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golang.org/x/oauth2"
)

const RepoOwner = "camunda"
Expand All @@ -22,12 +24,20 @@ const IdentityRepoName = "identity"
const ReleaseNotesTemplateFileName = "release-notes-template.txt"

type CamundaPlatformRelease struct {
Overview string
ZeebeReleaseNotes string
OperateReleaseNotes string
TasklistReleaseNotes string
IdentityReleaseNotes string
}

type camundaAppVersions struct {
Zeebe string
Operate string
Tasklist string
Identity string
}

func GetChangelogReleaseContents(ctx context.Context,
repoName string,
changelogFileName string,
Expand Down Expand Up @@ -83,13 +93,44 @@ func GetLatestReleaseContents(ctx context.Context,
return *githubRelease.Body
}

func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}

func releaseOverview(cav camundaAppVersions) string {
releaseOverview := `
Camunda application in this release generation:
- Identity: %s
- Operate: %s
- Tasklist: %s
- Zeebe: %s
`
return fmt.Sprintf(releaseOverview,
cav.Identity,
cav.Operate,
cav.Tasklist,
cav.Zeebe,
)
}

func main() {
var temp = template.Must(template.ParseFiles(ReleaseNotesTemplateFileName))

camundaTokenSource := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_CAMUNDA_ACCESS_TOKEN")},
)
githubRef := os.Getenv("GITHUB_REF_NAME")

camundaReleaseVersion := getEnv(os.Getenv("CAMUNDA_RELEASE_NAME"), os.Getenv("GITHUB_REF_NAME"))
camundaAppVersions := camundaAppVersions{
Operate: getEnv("OPERATE_GITREF", camundaReleaseVersion),
Tasklist: getEnv("TASKLIST_GITREF", camundaReleaseVersion),
Identity: getEnv("IDENTITY_GITREF", camundaReleaseVersion),
Zeebe: getEnv("ZEEBE_GITREF", camundaReleaseVersion),
}

ctx := context.TODO()
camundaOAuthClient := oauth2.NewClient(ctx, camundaTokenSource)

Expand All @@ -100,30 +141,30 @@ func main() {

camundaRepoService := camundaGithubClient.Repositories

log.Debug().Msg("Github ref = " + githubRef)
log.Debug().Msg("Camunda Github ref = " + camundaReleaseVersion)

zeebeReleaseNotes := GetLatestReleaseContents(
ctx,
RepoOwner,
ZeebeRepoName,
camundaRepoService,
githubRef,
camundaAppVersions.Zeebe,
)

operateReleaseNotesContents := GetLatestReleaseContents(
ctx,
RepoOwner,
OperateRepoName,
camundaRepoService,
githubRef,
camundaAppVersions.Operate,
)

tasklistReleaseNotesContents := GetChangelogReleaseContents(
ctx,
TasklistRepoName,
"CHANGELOG.md",
camundaRepoService,
githubRef,
camundaAppVersions.Tasklist,
)

camundaCloudTokenSource := oauth2.StaticTokenSource(
Expand All @@ -138,10 +179,15 @@ func main() {
CloudRepoOwner,
IdentityRepoName,
camundaCloudRepoService,
githubRef,
camundaAppVersions.Identity,
)

// Remove the Zeebe version at the beginning of Zeebe release notes to avoid confusion.
zeebeRegex := regexp.MustCompile(`# Release 8\..+\n`)
zeebeReleaseNotes = zeebeRegex.ReplaceAllString(zeebeReleaseNotes, "")

platformRelease := CamundaPlatformRelease{
Overview: releaseOverview(camundaAppVersions),
ZeebeReleaseNotes: zeebeReleaseNotes,
OperateReleaseNotes: operateReleaseNotesContents,
TasklistReleaseNotes: tasklistReleaseNotesContents,
Expand Down
52 changes: 0 additions & 52 deletions release-notes-fetcher/release.sh

This file was deleted.

0 comments on commit d478e86

Please sign in to comment.