Skip to content
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
70 changes: 70 additions & 0 deletions .github/actions/artifactory-oidc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: "Artifactory OIDC Auth"
description: "Exchange GitHub OIDC token for Artifactory access token and configure Bundler"

inputs:
artifactory-url:
description: "JFrog platform base URL. Falls back to ARTIFACTORY_URL env var."
required: false
default: ""
oidc-provider-name:
description: "OIDC provider name configured in Artifactory"
required: false
default: "github-actions-segmentio"
gems-repo:
description: "Artifactory virtual RubyGems repository name"
required: false
default: "virtual-gems-thirdparty"

runs:
using: "composite"
steps:
- name: Exchange GitHub OIDC token for Artifactory token
shell: bash
env:
INPUT_ARTIFACTORY_URL: ${{ inputs.artifactory-url }}
OIDC_PROVIDER_NAME: ${{ inputs.oidc-provider-name }}
GEMS_REPO: ${{ inputs.gems-repo }}
run: |
set -euo pipefail
ARTIFACTORY_URL="${INPUT_ARTIFACTORY_URL:-${ARTIFACTORY_URL:-}}"
if [ -z "${ARTIFACTORY_URL}" ]; then
echo "::error::ARTIFACTORY_URL is not set (pass as input or set as env var)"; exit 1
fi

OIDC_JWT=$(curl -sS \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=${ARTIFACTORY_URL}" \
-H "Authorization: Bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" | jq -r '.value')

if [ -z "$OIDC_JWT" ] || [ "$OIDC_JWT" = "null" ]; then
echo "::error::Failed to obtain GitHub OIDC token"; exit 1
fi

decode_seg() { local s="${1}"; local m=$(( ${#s} % 4 )); [ $m -ne 0 ] && s="${s}$(printf '=%.0s' $(seq 1 $((4-m))))"; echo "$s" | tr '_-' '/+' | base64 -d 2>/dev/null; }
PAYLOAD=$(decode_seg "$(echo "$OIDC_JWT" | cut -d. -f2)")
echo "OIDC token claims:"
echo " sub = $(echo "$PAYLOAD" | jq -r '.sub')"
echo " aud = $(echo "$PAYLOAD" | jq -r '.aud')"
echo " iss = $(echo "$PAYLOAD" | jq -r '.iss')"

RESP=$(curl -sS "${ARTIFACTORY_URL}/access/api/v1/oidc/token" \
-H 'Content-Type: application/json' \
-d "{\"grant_type\":\"urn:ietf:params:oauth:grant-type:token-exchange\",
\"subject_token_type\":\"urn:ietf:params:oauth:token-type:id_token\",
\"subject_token\":\"${OIDC_JWT}\",
\"provider_name\":\"${OIDC_PROVIDER_NAME}\"}")

ART_TOKEN=$(echo "$RESP" | jq -r '.access_token // empty')

if [ -z "$ART_TOKEN" ]; then
echo "::error::OIDC token exchange failed."
echo "$RESP" | jq 'if .access_token then .access_token="<redacted>" else . end' 2>/dev/null || echo "$RESP"
exit 1
fi
echo "::add-mask::$ART_TOKEN"

HOST=$(echo "${ARTIFACTORY_URL}" | sed -E 's#^https?://##')
MIRROR_URL="https://${HOST}/artifactory/api/gems/${GEMS_REPO}/"

bundle config mirror.https://rubygems.org "${MIRROR_URL}"
bundle config "https://${HOST}/artifactory/api/gems/${GEMS_REPO}/" ":${ART_TOKEN}"
echo "Configured Bundler to resolve through Artifactory (${GEMS_REPO})"
108 changes: 108 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

permissions:
id-token: write
contents: read

env:
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}

jobs:
lint:
name: Lint
runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }}

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Set up Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: '3.3'
bundler-cache: true

- name: Authenticate with Artifactory
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/artifactory-oidc
with:
artifactory_url: ${{ env.ARTIFACTORY_URL }}

- name: Install dependencies
run: bundle install

- name: Run RuboCop
run: bundle exec rubocop

test:
name: Test (Ruby ${{ matrix.ruby-version }})
runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }}
strategy:
fail-fast: false
matrix:
ruby-version: ['3.1', '3.2', '3.3']

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Set up Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Authenticate with Artifactory
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/artifactory-oidc
with:
artifactory_url: ${{ env.ARTIFACTORY_URL }}

- name: Install dependencies
run: bundle install

- name: Run tests
run: bundle exec rake

build:
name: Build
runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }}
needs: [lint, test]

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Set up Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: '3.3'
bundler-cache: true

- name: Authenticate with Artifactory
if: ${{ !github.event.pull_request.head.repo.fork }}
uses: ./.github/actions/artifactory-oidc
with:
artifactory_url: ${{ env.ARTIFACTORY_URL }}

- name: Install dependencies
run: bundle install

- name: Build gem
run: gem build analytics-ruby.gemspec

- name: Verify gem is installable
run: gem install ./analytics-ruby-*.gem

- name: Upload gem artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: analytics-ruby-gem
path: analytics-ruby-*.gem
if-no-files-found: error
62 changes: 62 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Release

on:
release:
types: [published]

permissions:
id-token: write
contents: read

env:
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}

jobs:
test:
name: Verify
runs-on: ubuntu-x64

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Set up Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: '3.3'
bundler-cache: true

- name: Authenticate with Artifactory
uses: ./.github/actions/artifactory-oidc
with:
artifactory_url: ${{ env.ARTIFACTORY_URL }}

- name: Install dependencies
run: bundle install

- name: Run tests
run: bundle exec rake

deploy:
name: Publish to RubyGems
runs-on: ubuntu-x64
needs: [test]
environment: rubygems
permissions:
id-token: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4

- name: Set up Ruby
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: '3.3'

- name: Build gem
run: gem build analytics-ruby.gemspec

- name: Publish to RubyGems (Trusted Publishing)
uses: rubygems/release-gem@612653d273a73bdba6a52d58baaac4a0d1aa8374 # v1
22 changes: 14 additions & 8 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@ on:
required: false
default: 'main'

permissions:
id-token: write
contents: read

env:
ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }}

jobs:
e2e-tests:
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || !github.event.pull_request.head.repo.fork }}
runs-on: ${{ github.event.pull_request.head.repo.fork && 'ubuntu-latest' || 'ubuntu-x64' }}

steps:
- name: Checkout SDK
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
path: sdk

- name: Checkout sdk-e2e-tests
uses: actions/checkout@v4
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: segmentio/sdk-e2e-tests
ref: ${{ inputs.e2e_tests_ref || 'main' }}
token: ${{ secrets.E2E_TESTS_TOKEN }}
path: sdk-e2e-tests

- name: Setup Ruby
uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@a2bbe5b1b236842c1cb7dd11e8e01a7b8b7f2007 # v1
with:
ruby-version: '3.2'
ruby-version: '3.3'

- name: Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -50,7 +56,7 @@ jobs:

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: e2e-test-results
path: sdk-e2e-tests/test-results/
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*.gem
Gemfile.lock
.ruby-version
coverage/
.claude/
Loading