diff --git a/.github/workflows/version-and-publish.yml b/.github/workflows/version-and-publish.yml index c8f1b90..681fb57 100644 --- a/.github/workflows/version-and-publish.yml +++ b/.github/workflows/version-and-publish.yml @@ -1,6 +1,7 @@ name: Validate and Publish on: + workflow_dispatch: pull_request: types: [closed] branches: @@ -12,7 +13,7 @@ permissions: jobs: build: - if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/v') + if: github.event_name == 'workflow_dispatch' || (github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/v')) runs-on: ubuntu-latest outputs: version: ${{ steps.extract-version.outputs.version }} @@ -21,16 +22,21 @@ jobs: - name: Checkout uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Extract and validate version from branch name + - name: Extract and validate version id: extract-version run: | - VERSION="${GITHUB_HEAD_REF#release/}" + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + VERSION="v$(jq -r '.gemVersion' turnkey_client_inputs/config.json)" + echo "Read version from config.json: $VERSION" + else + VERSION="${GITHUB_HEAD_REF#release/}" + echo "Extracted version from branch: $VERSION" + fi if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "::error::Branch name does not match expected format release/vX.X.X (got: $GITHUB_HEAD_REF)" + echo "::error::Version does not match expected format vX.X.X (got: $VERSION)" exit 1 fi echo "version=$VERSION" >> "$GITHUB_OUTPUT" - echo "Extracted version: $VERSION" # https://github.com/ruby/setup-ruby - name: Set up Ruby diff --git a/turnkey_client/lib/turnkey_client/api_client.rb b/turnkey_client/lib/turnkey_client/api_client.rb index cc85c60..46d7c07 100644 --- a/turnkey_client/lib/turnkey_client/api_client.rb +++ b/turnkey_client/lib/turnkey_client/api_client.rb @@ -38,6 +38,7 @@ def initialize(config) @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent + 'X-Client-Version' => "turnkey-ruby/#{VERSION}" } if config.api_public_key.nil? diff --git a/turnkey_client_inputs/templates/api_client.mustache b/turnkey_client_inputs/templates/api_client.mustache index 79d3871..e60ba44 100644 --- a/turnkey_client_inputs/templates/api_client.mustache +++ b/turnkey_client_inputs/templates/api_client.mustache @@ -32,6 +32,7 @@ module {{moduleName}} @default_headers = { 'Content-Type' => 'application/json', 'User-Agent' => @user_agent + 'X-Client-Version' => "turnkey-ruby/#{VERSION}" } if config.api_public_key.nil?