Skip to content

Commit

Permalink
GHA to create tag/release
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigozhou committed Dec 10, 2024
1 parent 38d2ac0 commit 7db666c
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/create-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: "Create a tag"

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
create_release:
description: "Create release and set as latest"
type: boolean
default: 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
default: false

jobs:
create-tag:
name: "Create a tag"
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: ${{ inputs.branch }}
token: ${{ steps.generate_token.outputs.token }}
persist-credentials: true
fetch-depth: 0
fetch-tags: true

- name: Set up Github credentials
run: |
git config --local user.name 'Temporal Data'
git config --local user.email '[email protected]'
- name: Prepare new version string
id: new_version
env:
TAG: ${{ inputs.tag }}
run: |
if [[ "${TAG}" =~ ^v.* ]]; then
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
else
echo "tag=v${TAG}" >> "$GITHUB_OUTPUT"
fi
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Validate input
env:
BRANCH: ${{ inputs.branch }}
TAG: ${{ steps.new_version.outputs.tag }}
CREATE_RELEASE: ${{ inputs.create_release }}
BASE_TAG: ${{ inputs.base_tag }}
run: |
if [[ -n "$(git tag -l "$TAG")" && "$(git rev-parse "$TAG")" != "$(git rev-parse HEAD)" ]]; then
echo "::error::Tag already exists and it doesn't reference current HEAD of branch $BRANCH"
exit 1
fi
if [[ "$CREATE_RELEASE" == "true" ]]; then
if [[ -z "$BASE_TAG" || -z "$(git tag -l "$BASE_TAG")" ]]; then
echo "::error::Base tag not specified or does not exist"
exit 1
fi
fi
- name: Pin api-go commit sha
id: pin-api-go
env:
BRANCH: ${{ inputs.branch }}
run: |
API_GO_COMMIT_SHA=$(gh api /repos/temporalio/api-go/branches/$BRANCH --jq '.commit.sha')
echo "API_GO_COMMIT_SHA=$API_GO_COMMIT_SHA" >> "$GITHUB_OUTPUT"
- name: Check compatibility with sdk-go
if: ${{ inputs.skip_sdk_check == 'false' }}
uses: temporalio/sdk-go/.github/workflows/check-api-go.yml@master
with:
sdk_commit: latest
api_commit: ${{ steps.pin-api-go.outputs.API_GO_COMMIT_SHA }}

- name: Create and push tag
env:
BRANCH: ${{ inputs.branch }}
TAG: ${{ steps.new_version.outputs.tag }}
run: |
if [[ -z "$(git tag -l "$TAG")" ]]; then
git tag "$TAG"
git push origin "$TAG"
fi
- name: Create release
if: ${{ inputs.create_release == 'true' }}
env:
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
TAG: ${{ steps.new_version.outputs.tag }}
BASE_TAG: ${{ inputs.base_tag }}
run: |
gh repo set-default ${{ github.repository }}
gh release create "$TAG" --verify-tag --latest --generate-notes --notes-start-tag "$BASE_TAG"
- name: Release api-go
if: ${{ inputs.create_release == 'true' }}
uses: temporalio/api-go/.workflows/create-tag.yml@master
with:
token: ${{ steps.generate_token.outputs.token }}
ref: ${{ steps.pin-api-go.outputs.API_GO_COMMIT_SHA }}
tag: ${{ steps.new_version.outputs.tag }}
create_release: true
base_tag: ${{ inputs.base_tag }}

0 comments on commit 7db666c

Please sign in to comment.