From f72a00c586570b11e81f5299a5322a72b14dee65 Mon Sep 17 00:00:00 2001 From: Natalie Bunduwongse Date: Fri, 26 Jul 2024 17:40:51 +1200 Subject: [PATCH] ci: update update-version.xml, add tag workflow which creates a release --- .github/scripts/check_team_membership.sh | 22 +++++++ .github/workflows/release.yml | 10 ++-- .github/workflows/tag.yml | 36 ++++++++++++ .github/workflows/update-version.yml | 75 ++++++++++++++---------- 4 files changed, 109 insertions(+), 34 deletions(-) create mode 100755 .github/scripts/check_team_membership.sh create mode 100644 .github/workflows/tag.yml diff --git a/.github/scripts/check_team_membership.sh b/.github/scripts/check_team_membership.sh new file mode 100755 index 0000000..49a47e5 --- /dev/null +++ b/.github/scripts/check_team_membership.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -x + +USER=$1 + +response=$(gh api \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "/orgs/immutable/teams/sdk/memberships/${USER}") + +echo "$response" + +if echo "$response" | grep -q '"state":"active"'; then + IS_MEMBER=true +else + IS_MEMBER=false +fi +echo "$IS_MEMBER" + +# Set the environment variable for the GitHub workflow +echo "IS_MEMBER=$IS_MEMBER" >> "$GITHUB_ENV" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4f8174b..fcec8ab 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,13 +1,15 @@ --- name: 'Create Release' + on: - push: - tags: - - '*' + workflow_run: + workflows: ["Tag Release"] + types: + - completed jobs: release: - if: startsWith(github.ref, 'refs/tags/') + if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 0000000..427f8be --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,36 @@ +--- +name: "Tag Release" + +on: + pull_request: + types: [closed] + +jobs: + create-tag: + if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Extract version from ImmutableDataTypes.h + id: extract_version + run: | + version=$(grep -oP '#define ENGINE_SDK_VERSION TEXT\("\K[0-9]+\.[0-9]+\.[0-9]+' ImmutableDataTypes.h) + + if [[ -z "$version" ]]; then + echo "Error: Version not found in ImmutableDataTypes.h" >&2 + exit 1 + fi + + version=$(echo "$version" | tr -d '\r\n') + + echo "VERSION=${version}" >> "$GITHUB_ENV" + + - name: Create Tag + uses: negz/create-tag@v1 + with: + version: "v${{ env.VERSION }}" + message: "Version ${{ env.VERSION }}" + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/update-version.yml b/.github/workflows/update-version.yml index 6a8386d..844800c 100644 --- a/.github/workflows/update-version.yml +++ b/.github/workflows/update-version.yml @@ -1,32 +1,47 @@ --- - name: "Update engine SDK version in Immutable Data Types" - - on: - workflow_dispatch: - inputs: - version: - description: 'Version to update to (e.g. 1.20.0)' - required: true - - jobs: - update: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 +name: "Update engine SDK version in ImmutableDataTypes.h" - # - name: Check team membership - # id: check_team - # run: | - # IS_MEMBER=$(./.github/scripts/check_team_membership.sh "${{ github.actor }}" "${{ secrets.GITHUB_TOKEN }}") - # if [[ "$IS_MEMBER" != "true" ]]; then - # echo "Not a member of the SDK team, skipping update" - # exit 1 - # fi - - - name: Replace engine sdk version string - id: replace_engine_sdk_version - run: | - FILE=./Source/Immutable/Public/Immutable/ImmutableDataTypes.h - VERSION=${{ github.event.inputs.version }} - sed -i -E "s/#define ENGINE_SDK_VERSION TEXT\(\"[0-9]+\.[0-9]+\.[0-9]+\"\)/#define ENGINE_SDK_VERSION TEXT(\"$VERSION\")/g" $FILE +on: + workflow_dispatch: + inputs: + version: + description: 'Version to update to (e.g. 1.20.0)' + required: true + +jobs: + update: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.UNREAL_IMMUTABLE_SDK_GITHUB_TOKEN }} + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check team membership + id: check_team + run: | + ./.github/scripts/check_team_membership.sh "${{ github.actor }}" "${{ secrets.UNREAL_IMMUTABLE_SDK_GITHUB_TOKEN }}" + # shellcheck disable=SC1090 + source "$GITHUB_ENV" + echo "${{ github.actor }} is a member of the SDK team: $IS_MEMBER" + if [[ "$IS_MEMBER" != "true" ]]; then + echo "Not a member of the SDK team, skipping update" + exit 1 + fi + + - name: Replace engine sdk version string + id: replace_engine_sdk_version + run: | + FILE=./Source/Immutable/Public/Immutable/ImmutableDataTypes.h + VERSION=${{ github.event.inputs.version }} + sed -i -E "s/#define ENGINE_SDK_VERSION TEXT\(\"[0-9]+\.[0-9]+\.[0-9]+\"\)/#define ENGINE_SDK_VERSION TEXT(\"$VERSION\")/g" $FILE + + - uses: gr2m/create-or-update-pull-request-action@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + title: "release: update version" + body: "Update version in ImmutableDataTypes.h" + branch: "release/update-version" + commit-message: "release: update version" + labels: release