From 4e20b6db005b9bee4ccf5413ff2da889d1c6c0df Mon Sep 17 00:00:00 2001 From: rodrigozhou Date: Wed, 11 Dec 2024 03:15:06 +0800 Subject: [PATCH 1/2] GHA to create tags/releases --- .github/workflows/create-tag.yml | 106 +++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/create-tag.yml diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-tag.yml new file mode 100644 index 00000000..26d52f88 --- /dev/null +++ b/.github/workflows/create-tag.yml @@ -0,0 +1,106 @@ +name: "Create a tag" + +on: + workflow_call: + inputs: + ref: + description: "Ref to be tagged" + required: true + type: string + default: master + tag: + description: "Tag for new version (v1.23.4)" + required: true + type: string + 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 + type: string + secrets: + TEMPORAL_CICD_APP_ID: + required: true + TEMPORAL_CICD_PRIVATE_KEY: + required: true + +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: + repository: temporalio/api-go + ref: ${{ github.event.inputs.ref }} + token: ${{ steps.generate_token.outputs.token }} + persist-credentials: true + fetch-depth: 0 + fetch-tags: true + submodules: true + + - name: Set up Github credentials + run: | + git config --local user.name 'Temporal Data' + git config --local user.email 'commander-data@temporal.io' + + - name: Prepare new version string + id: new_version + env: + TAG: ${{ github.event.inputs.tag }} + run: | + if [[ "${TAG}" =~ ^v.* ]]; then + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + else + echo "tag=v${TAG}" >> "$GITHUB_OUTPUT" + fi + + - name: Validate input + env: + REF: ${{ github.event.inputs.ref }} + TAG: ${{ steps.new_version.outputs.tag }} + CREATE_RELEASE: ${{ github.event.inputs.create_release }} + BASE_TAG: ${{ github.event.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 $REF" + 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: Create and push tag + env: + 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: ${{ github.event.inputs.create_release == true || github.event.inputs.create_release == 'true' }} + env: + GH_TOKEN: ${{ steps.generate_token.outputs.token }} + TAG: ${{ steps.new_version.outputs.tag }} + BASE_TAG: ${{ github.event.inputs.base_tag }} + run: | + gh repo set-default ${{ github.repository }} + gh release create "$TAG" --verify-tag --latest --generate-notes --notes-start-tag "$BASE_TAG" From cafd8c799c9a234162d745b6e16f23f744c6209f Mon Sep 17 00:00:00 2001 From: rodrigozhou Date: Wed, 11 Dec 2024 11:51:19 -0800 Subject: [PATCH 2/2] address comments --- .../{create-tag.yml => create-release.yml} | 58 ++++++------------- 1 file changed, 18 insertions(+), 40 deletions(-) rename .github/workflows/{create-tag.yml => create-release.yml} (61%) diff --git a/.github/workflows/create-tag.yml b/.github/workflows/create-release.yml similarity index 61% rename from .github/workflows/create-tag.yml rename to .github/workflows/create-release.yml index 26d52f88..36784fb4 100644 --- a/.github/workflows/create-tag.yml +++ b/.github/workflows/create-release.yml @@ -1,4 +1,4 @@ -name: "Create a tag" +name: "Create a release" on: workflow_call: @@ -12,10 +12,6 @@ on: description: "Tag for new version (v1.23.4)" required: true type: string - 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 @@ -27,8 +23,8 @@ on: required: true jobs: - create-tag: - name: "Create a tag" + create-release: + name: "Create a release" runs-on: ubuntu-latest steps: @@ -51,56 +47,38 @@ jobs: fetch-tags: true submodules: true - - name: Set up Github credentials - run: | - git config --local user.name 'Temporal Data' - git config --local user.email 'commander-data@temporal.io' - - - name: Prepare new version string - id: new_version - env: - TAG: ${{ github.event.inputs.tag }} - run: | - if [[ "${TAG}" =~ ^v.* ]]; then - echo "tag=${TAG}" >> "$GITHUB_OUTPUT" - else - echo "tag=v${TAG}" >> "$GITHUB_OUTPUT" - fi - - name: Validate input env: REF: ${{ github.event.inputs.ref }} - TAG: ${{ steps.new_version.outputs.tag }} - CREATE_RELEASE: ${{ github.event.inputs.create_release }} + TAG: ${{ github.event.inputs.tag }} BASE_TAG: ${{ github.event.inputs.base_tag }} run: | + if ! [[ "${TAG}" =~ ^v.* ]]; then + echo "::error::Tag is not prefixed with 'v'" + exit 1 + fi + 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 $REF" 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 + 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: Create and push tag - env: - TAG: ${{ steps.new_version.outputs.tag }} + - name: Set up Github credentials run: | - if [[ -z "$(git tag -l "$TAG")" ]]; then - git tag "$TAG" - git push origin "$TAG" - fi + git config --local user.name 'Temporal Data' + git config --local user.email 'commander-data@temporal.io' - name: Create release - if: ${{ github.event.inputs.create_release == true || github.event.inputs.create_release == 'true' }} env: GH_TOKEN: ${{ steps.generate_token.outputs.token }} - TAG: ${{ steps.new_version.outputs.tag }} + REF: ${{ github.event.inputs.ref }} + TAG: ${{ github.event.inputs.tag }} BASE_TAG: ${{ github.event.inputs.base_tag }} run: | gh repo set-default ${{ github.repository }} - gh release create "$TAG" --verify-tag --latest --generate-notes --notes-start-tag "$BASE_TAG" + gh release create "$TAG" --target "$REF" --latest --generate-notes --notes-start-tag "$BASE_TAG"