Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GHA to create release #437

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: "Create release"

on:
workflow_dispatch:
inputs:
branch:
description: "Branch to be tagged"
required: true
default: master
tag:
description: "Tag for new version (v1.23.4)"
required: true
base_tag:
description: "Base tag to generate commit list for release notes"
required: false
skip_sdk_check:
description: "Skip sdk-go compatibility check"
type: boolean

jobs:
prepare-inputs:
name: "Prepare inputs"
runs-on: ubuntu-latest
outputs:
api_commit_sha: ${{ steps.pin_commits.outputs.api_commit_sha }}
api_go_commit_sha: ${{ steps.pin_commits.outputs.api_go_commit_sha }}
steps:
- name: Checkout api
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
fetch-depth: 0
fetch-tags: true
path: api

- name: Checkout api-go
uses: actions/checkout@v4
with:
repository: temporalio/api-go
ref: ${{ github.event.inputs.branch }}
submodules: true
path: api-go

- name: Validate inputs
env:
BRANCH: ${{ github.event.inputs.branch }}
TAG: ${{ github.event.inputs.tag }}
BASE_TAG: ${{ github.event.inputs.base_tag }}
working-directory: ./api
run: |
if ! [[ "${TAG}" =~ ^v.* ]]; then
echo "::error::Tag is not prefixed with 'v'"
exit 1
fi

if [[ -n "$(git tag -l "$TAG")" ]]; then
echo "::error::Tag already exists"
exit 1
fi

if [[ -z "$BASE_TAG" || -z "$(git tag -l "$BASE_TAG")" ]]; then
echo "::error::Base tag not specified or does not exist"
exit 1
fi

- name: Pin commits sha
id: pin_commits
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: ${{ github.event.inputs.branch }}
run: |
API_COMMIT_SHA=$(git -C ./api rev-parse HEAD)
API_GO_COMMIT_SHA=$(git -C ./api-go rev-parse HEAD)
API_GO_API_COMMIT_SHA=$(git -C ./api-go rev-parse HEAD:proto/api)
if [[ "${API_GO_API_COMMIT_SHA}" != "${API_COMMIT_SHA}" ]]; then
echo "::error::api-go ref ${API_GO_COMMIT_SHA} does not reference api ref ${API_COMMIT_SHA}, api-go repo might not be up-to-date."
exit 1
fi
echo "api_commit_sha=$API_COMMIT_SHA" >> "$GITHUB_OUTPUT"
echo "api_go_commit_sha=$API_GO_COMMIT_SHA" >> "$GITHUB_OUTPUT"

check-compatibility-sdk-go:
needs: prepare-inputs
if: ${{ github.event.inputs.skip_sdk_check == false || github.event.inputs.skip_sdk_check == 'false' }}
uses: temporalio/api-go/.github/workflows/check-sdk-compat.yml@master
with:
sdk_ref: latest
api_ref: ${{ needs.prepare-inputs.outputs.api_go_commit_sha }}

create-release:
name: "Create release"
needs: [prepare-inputs, check-compatibility-sdk-go]
if: |
!cancelled() &&
needs.prepare-inputs.result == 'success' &&
contains(fromJSON('["success", "skipped"]'), needs.check-compatibility-sdk-go.result)
Comment on lines +93 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have imagined this would be the default, is it not so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github actions doesn't work well when the dependency has a condition for running.
In this case, the check-compatibility-sdk-go job runs only if the flag is set. So, even if I add it to needs, the create-release job never runs. So, I need to manually check the conditions.

runs-on: ubuntu-latest

steps:
- name: Generate token
id: generate_token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.TEMPORAL_CICD_APP_ID }}
private-key: ${{ secrets.TEMPORAL_CICD_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare-inputs.outputs.api_commit_sha }}
token: ${{ steps.generate_token.outputs.token }}

- name: Create release
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
REF: ${{ needs.prepare-inputs.outputs.api_commit_sha }}
TAG: ${{ github.event.inputs.tag }}
BASE_TAG: ${{ github.event.inputs.base_tag }}
run: |
gh repo set-default ${{ github.repository }}
gh release create "$TAG" --target "$REF" --latest --generate-notes --notes-start-tag "$BASE_TAG" --draft

release-api-go:
needs: [prepare-inputs, create-release]
if: |
!cancelled() &&
needs.create-release.result == 'success'
uses: temporalio/api-go/.github/workflows/create-release.yml@master
with:
ref: ${{ needs.prepare-inputs.outputs.api_go_commit_sha }}
tag: ${{ github.event.inputs.tag }}
api_commit_sha: ${{ needs.prepare-inputs.outputs.api_commit_sha }}
base_tag: ${{ github.event.inputs.base_tag }}
secrets: inherit
13 changes: 13 additions & 0 deletions .github/workflows/trigger-api-go-delete-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Trigger api-go delete release"

on:
release:
types: [deleted]

jobs:
trigger-api-go-delete-release:
uses: temporalio/api-go/.github/workflows/delete-release.yml@master
with:
tag: ${{ github.event.release.tag_name }}
api_commit_sha: ${{ github.event.release.target_commitish }}
secrets: inherit
13 changes: 13 additions & 0 deletions .github/workflows/trigger-api-go-publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Trigger api-go publish release"

on:
release:
types: [published]

jobs:
trigger-api-go-publish-release:
uses: temporalio/api-go/.github/workflows/publish-release.yml@master
with:
tag: ${{ github.event.release.tag_name }}
api_commit_sha: ${{ github.event.release.target_commitish }}
secrets: inherit
Loading