-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Install the Flagsmith CLI and authenticate it via OIDC #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
504865e
feat: install the CLI and exchange the job's OIDC token
khvn26 5946040
refactor: delegate installation to the CLI's own installers
khvn26 4864241
refactor: drop the action's outputs
khvn26 ca672a5
refactor: collapse the platform branches and drop the unread token type
khvn26 f6bee56
refactor: stop pre-checking for curl and wget
khvn26 236cb00
refactor: look failure hints up in a table
khvn26 85d7cbc
refactor: inline the version helpers into resolveVersion
khvn26 1275a2d
test: read a real event file instead of injecting a reader
khvn26 d0db1b8
refactor: order each module public-first and high-level-first
khvn26 b724eb0
fix: show the error body whatever its content type
khvn26 f409361
refactor: find the folded credential name in one expression
khvn26 1be14d4
style: drop a blank line from an import list
khvn26 5b8aebd
refactor: inline the api-url normalisation into its only caller
khvn26 3afe754
refactor: normalise api-url with the URL parser
khvn26 e9123ad
refactor: read GITHUB_TOKEN where it is used
khvn26 2b14fa1
refactor: one error for a release response we cannot read
khvn26 9f75a39
fix: show the release response body when it cannot be read
khvn26 656147b
refactor: let the installer choose the latest release
khvn26 aa07fd1
feat: resolve an unpinned version with the installer's dry run
khvn26 4b1588f
fix: degrade to an uncached install when the dry run says nothing
khvn26 7195aac
refactor: inline the dry-run parse into installCli
khvn26 570516f
feat: fall back to the installed binary for the cache key
khvn26 a48eb3b
refactor: take the version straight from the binary's output
khvn26 fe69ab5
refactor: one truthiness test for the resolved version
khvn26 2396f60
refactor: name the installer scripts with a literal union
khvn26 93c6ead
refactor: split the entrypoint from the action logic
khvn26 b3eaa99
refactor: one throw for a response that is not a 200
khvn26 fd43813
improve docs
khvn26 dd357b9
chore: pre-commit, security-only renovate, release-please, PR tests
khvn26 01ce478
chore: pin workflow actions to commit SHAs
khvn26 b501213
chore: drop the CI test workflow
khvn26 e0f39f3
fix: name the version that ships the exchange endpoint
khvn26 229ecac
improve docs
khvn26 610d53c
chore: empty commit to trigger CI
khvn26 41ea715
chore: skip the npm hooks on pre-commit.ci
khvn26 64c1b59
ci: replace CI-duplicating pre-commit hooks with linting hooks
khvn26 7a998a7
docs: clarify the audience input default
khvn26 0d93bef
docs: show a conventional bring-your-own-key example
khvn26 cd8cc94
docs: stop enumerating the exported environment variables
khvn26 ee4a8c0
ci: keep the README usage examples on the released major
khvn26 025d1ad
refactor: split constants out of a renamed credentials module
khvn26 c1b5161
fix: look up unscoped credentials by their exact name, as the CLI does
khvn26 7eaf216
docs: describe fetchOk in plain language
khvn26 8adfee8
refactor: return installer behavior instead of an argument bag
khvn26 b4ed3d5
refactor: inline the case-insensitive lookup at its only call site
khvn26 e393d0d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 467d113
refactor: rename fetchOk to fetchOrThrow
khvn26 e9658c0
refactor: name the install steps for what they do
khvn26 d4b6af8
docs: explain scoped and unscoped credential names
khvn26 77791f0
push major tag so all example snippets actually work
khvn26 e7dd140
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] cd32a6d
test: cover every exchangeFailureHint mapping and unescape a test name
khvn26 98c2c6c
test: unit test every exchangeFailureHint status mapping
khvn26 99b3e89
skip bumping major tag for prereleases
khvn26 1992dbf
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] eb2f097
test: replace the mock-server exchange tests with a real smoke test
khvn26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Pull request | ||
|
|
||
| on: pull_request | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: 24 | ||
| cache: npm | ||
| - run: npm ci | ||
| - run: npx vitest run | ||
|
|
||
| test-e2e: | ||
| runs-on: ubuntu-latest | ||
| environment: test | ||
| permissions: | ||
| id-token: write | ||
| contents: read | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: ./ | ||
| with: | ||
| api-url: https://api-staging.flagsmith.com | ||
| - run: flagsmith --version | ||
| - run: flagsmith flag list --project "Flagsmith/setup-cli E2E" -e E2E |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| name: Update major tag on release | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| permissions: | ||
| contents: write | ||
|
|
||
| jobs: | ||
| major-tag: | ||
| if: ${{ !github.event.release.prerelease }} | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - id: get-major-tag | ||
| run: | | ||
| major="v${GITHUB_REF_NAME#v}"; major="v${major%%.*}" | ||
| echo "result=$major" >> "$GITHUB_OUTPUT" | ||
| - name: Bump ${{ steps.get-major-tag.outputs.result }} | ||
| run: | | ||
| # Point the floating major tag at this release | ||
| # Makes `uses: Flagsmith/setup-cli@v1` work | ||
| git tag -f "${{ steps.get-major-tag.outputs.result }}" "$GITHUB_REF_NAME" | ||
| git push -f origin "${{ steps.get-major-tag.outputs.result }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules/ | ||
| lib/ | ||
| *.tsbuildinfo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| exclude: ^dist/ | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v6.0.0 | ||
| hooks: | ||
| - id: check-yaml | ||
| - id: check-json | ||
| - id: check-merge-conflict | ||
| - id: end-of-file-fixer | ||
| - id: trailing-whitespace | ||
|
|
||
| - repo: https://github.com/rbubley/mirrors-prettier | ||
| rev: v3.9.6 | ||
| hooks: | ||
| - id: prettier | ||
| types_or: [ts, json, yaml, markdown] | ||
|
|
||
| - repo: https://github.com/rhysd/actionlint | ||
| rev: v1.7.12 | ||
| hooks: | ||
| - id: actionlint | ||
|
|
||
| - repo: https://github.com/python-jsonschema/check-jsonschema | ||
| rev: 0.38.0 | ||
| hooks: | ||
| - id: check-github-workflows | ||
| - id: check-renovate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "semi": false, | ||
| "singleQuote": true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| ".": "1.0.0" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,69 @@ | ||
| # setup-cli | ||
| 鈻讹笍 GitHub Action to download and install the Flagsmith CLI | ||
| # `Flagsmith/setup-cli` | ||
|
|
||
| Install the [Flagsmith CLI](https://github.com/Flagsmith/flagsmith-cli) in a GitHub Actions job, and authenticate it without storing a secret. | ||
|
|
||
| ## Usage | ||
|
|
||
| <!-- x-release-please-start-major --> | ||
|
|
||
| ```yaml | ||
| jobs: | ||
| flagsmith: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| id-token: write # required for the token exchange | ||
| contents: read | ||
| steps: | ||
| - uses: Flagsmith/setup-cli@v1 | ||
| - run: flagsmith auth status | ||
| ``` | ||
|
|
||
| <!-- x-release-please-end --> | ||
|
|
||
| Or, with a static key: | ||
|
|
||
| <!-- x-release-please-start-major --> | ||
|
khvn26 marked this conversation as resolved.
|
||
|
|
||
| ```yaml | ||
| jobs: | ||
| flagsmith: | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| FLAGSMITH_API_KEY: ${{ secrets.FLAGSMITH_API_KEY }} | ||
| steps: | ||
| # Installs the CLI and skips the token exchange: | ||
| - uses: Flagsmith/setup-cli@v1 | ||
| - run: flagsmith flags list # uses your key | ||
| ``` | ||
|
|
||
| <!-- x-release-please-end --> | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Input | Default | Description | | ||
| | ------------- | --------------------------- | ------------------------------------------------------------------------------------------------------ | | ||
| | `api-url` | `https://api.flagsmith.com` | Flagsmith API base URL. Set this for self-hosted instances. | | ||
| | `audience` | `https://github.com/OWNER` | The `aud` claim to request. Only set this if your Flagsmith trust relationship uses a custom audience. | | ||
| | `cli-version` | `latest` | CLI version to install, e.g. `v2.0.0`. | | ||
|
|
||
| ## When the action skips authentication | ||
|
|
||
| The action always installs the CLI, but may skip authentication if: | ||
|
|
||
| - the run is a pull request from a fork. | ||
| - the job has no `id-token: write` permission. | ||
| - the job already carries a credential the CLI would use for this `api-url` (`FLAGSMITH_API_KEY` or `FLAGSMITH_ACCESS_TOKEN`, scoped to provided `api-url`). | ||
|
|
||
| ## After the action runs | ||
|
|
||
| The API URL and the exchanged access token are exported to the job environment, where the CLI picks them up. | ||
|
|
||
| The CLI binary is added to `PATH` via `GITHUB_PATH`, and cached in the runner tool cache by version and architecture. | ||
|
|
||
| ## Development | ||
|
|
||
| ```sh | ||
| npm ci | ||
| npm test # unit tests | ||
| npm run all # typecheck, test, and rebuild dist/ | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Setup Flagsmith CLI | ||
| description: >- | ||
| Install the Flagsmith CLI and, when the job has an OIDC identity, exchange it | ||
| for a short-lived Flagsmith access token. | ||
| author: Flagsmith | ||
| branding: | ||
| icon: flag | ||
| color: purple | ||
|
|
||
| inputs: | ||
| api-url: | ||
| description: Flagsmith API base URL. | ||
| required: false | ||
| default: https://api.flagsmith.com | ||
| audience: | ||
| description: >- | ||
| The `aud` claim to request for the GitHub OIDC token. Defaults to | ||
| GitHub's own default, https://github.com/OWNER. Only set this if your | ||
| Flagsmith trust relationship uses a custom audience. | ||
| required: false | ||
| default: '' | ||
| cli-version: | ||
| description: >- | ||
| Version of the CLI to install, e.g. `v2.0.0`. Defaults to the latest | ||
| release. | ||
| required: false | ||
| default: latest | ||
|
|
||
| runs: | ||
| using: node24 | ||
| main: dist/index.cjs |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.