Integrate Polar into your GitHub Actions workflows easily thanks to our ready-to-use actions.
This action allows you to generate a temporary Polar API token for your workflow, without the need to generate a long-lived personal access token.
You'll need to link the repository running the workflow to your Polar organization, as described here.
Your workflow will need the id-token
permission:
permissions:
id-token: write
You can then use the action like this:
- uses: polarsource/actions/auth@v1
id: polar
with:
scope: 'openid benefits:read products:read'
The only required parameter, scope
, is a space-separated list of scopes you want to grant to the resulting token. The token is available as an output of the action. For example, you can use it like this:
- name: 'Check Polar access'
run: |
resp=$(curl -XGET -H "Authorization: Bearer ${{ steps.polar.outputs.token }}" https://api.polar.sh/api/v1/oauth2/userinfo)
echo $resp
Note
The generated token is an organization access token.
Tip
How does it work?
We use GitHub OpenID Connect mechanism to authenticate the request truly comes for your repository's workflow. Since you've linked the repository on Polar, we can trust the action comes from you and deliver a short-lived token.
Tag an issue as priority
if the author has access to a specific benefit
name: Priority Issues
on:
issues:
types: [opened]
permissions:
id-token: write
contents: read
issues: write
env:
POLAR_BENEFIT_ID: 00000000-0000-0000-0000-000000000000
jobs:
check-priority:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: polarsource/actions/auth@v1
id: polar
with:
scope: 'benefits:read'
- name: 'Check if author has access to priority answers'
id: check-benefit
run: |
resp=$(curl -XGET -H "Authorization: Bearer ${{ steps.polar.outputs.token }}" https://api.polar.sh/api/v1/benefits/${{ env.POLAR_BENEFIT_ID }}/grants?is_granted=true&github_user_id=${{ github.event.issue.user.id }})
count=$(($(jq -r '.pagination | .total_count' <<< "${resp}")))
echo "count=$(echo $count)" >> $GITHUB_OUTPUT
- name: 'Add the priority label'
if: steps.check-benefit.outputs.count > 0
run: gh issue edit "$NUMBER" --add-label "$LABELS"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
NUMBER: ${{ github.event.issue.number }}
LABELS: priority
This action allows you to automatically synchronize the ads created by your customers as part of an Ad benefit in a Markdown or HTML page.
<!-- POLAR type=ads benefit_id=00000000-0000-0000-0000-000000000000 width=100 height=100 -->
benefit_id
is the ID of your ad benefit. You can find it in your dashboard, on the Benefits
page.
- name: Sync Polar ads
uses: polarsource/actions/ads@main
with:
path: README.md
token: ${{ secrets.POLAR_ACCESS_TOKEN }}
path
is the path of the file you want to update. Glob patterns are supported. token
is a valid Polar access token, which you can set in your repository secrets or generate using our auth action.
Update ads in README.md on push and every day
name: Ads sync example
on:
push:
branches: ["main"]
schedule:
- cron: "0 7 * * *"
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Check out code
uses: actions/checkout@v4
- uses: polarsource/actions/auth@v1
id: polar
with:
scope: 'openid'
- name: Sync Polar ads
uses: polarsource/actions/ads@v1
with:
path: README.md
token: ${{ steps.polar.outputs.token }}
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Update Polar ads