Skip to content

feat: distributor protocol level fees #166

feat: distributor protocol level fees

feat: distributor protocol level fees #166

name: Alpha Release
on:
workflow_dispatch:
inputs:
pr_number:
description: 'PR number (for manual runs)'
required: true
pull_request:
branches:
- master
jobs:
resolve-alpha:
runs-on: ubuntu-latest
outputs:
alpha_version: ${{ steps.set_alpha_version.outputs.alpha_version }}
pr_number: ${{ steps.set_alpha_version.outputs.pr_number }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref }}
- name: Resolve alpha version
id: set_alpha_version
run: |
BASE_VERSION=$(node -p 'require("./lerna.json").version')
SHORT_SHA=$(git rev-parse --short HEAD)
ALPHA_VERSION=""
PR_NUMBER=""
if [ "${{ github.event_name }}" = "pull_request" ]; then
BRANCH="${{ github.head_ref }}"
if [[ "$BRANCH" == alpha/* ]]; then
message=$(git log -1 --pretty=%B | head -n 1)
if [[ "$message" != *'[skip alpha]'* ]]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
ALPHA_VERSION="${BASE_VERSION}-alpha.p${PR_NUMBER}.${SHORT_SHA}"
fi
fi
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
PR_NUMBER="${{ github.event.inputs.pr_number }}"
if [ -n "$PR_NUMBER" ]; then
ALPHA_VERSION="${BASE_VERSION}-alpha.p${PR_NUMBER}.${SHORT_SHA}"
fi
fi
echo "alpha_version=$ALPHA_VERSION" >> $GITHUB_OUTPUT
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
echo "ALPHA_VERSION=$ALPHA_VERSION"
echo "PR_NUMBER=$PR_NUMBER"
tests:
if: needs.resolve-alpha.outputs.alpha_version != ''
needs: resolve-alpha
uses: ./.github/workflows/version-tests.yml
all-tests-pass:
if: needs.resolve-alpha.outputs.alpha_version != ''
runs-on: ubuntu-latest
needs: [tests, resolve-alpha]
steps:
- run: echo "All tests completed"
publish-alpha:
if: needs.resolve-alpha.outputs.alpha_version != ''
runs-on: ubuntu-latest
needs: [all-tests-pass, resolve-alpha]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 22
cache: "pnpm"
registry-url: https://registry.npmjs.org/
- name: Install dependencies
run: pnpm install
- name: Version all packages
run: pnpm version-all ${{ needs.resolve-alpha.outputs.alpha_version }} -y
- name: Git status
run: git status
- name: Commit version changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add -A
git commit -m "chore: version bump to ${{ needs.resolve-alpha.outputs.alpha_version }} [skip ci]" --no-verify || echo "No changes to commit"
- name: Git status after
run: git status
- name: Build packages
run: pnpm build
- name: Validate NPM Token
run: |
echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > .npmrc
npm whoami
rm -f .npmrc
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
- name: Publish Alpha
run: npm run publish -- --dist-tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Add comment to PR
uses: actions/github-script@v4
continue-on-error: true
env:
PR_NUMBER: ${{ needs.resolve-alpha.outputs.pr_number }}
ALPHA_VERSION: ${{ needs.resolve-alpha.outputs.alpha_version }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const prNumber = process.env.PR_NUMBER || (context.issue && context.issue.number);
const alphaVersion = process.env.ALPHA_VERSION;
if (!prNumber) {
core.warning('No PR number available to comment on.');
return;
}
const comments = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const botComment = comments.data.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('Alpha versions of packages are published')
);
const commentBody = `Alpha versions of packages are published 📦\n\n` +
`PR: #${prNumber}\n` +
`Version: ${alphaVersion}\n` +
`NPM: https://www.npmjs.com/package/@streamflow/common/v/${alphaVersion}`;
if (botComment) {
await github.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: commentBody
});
} else {
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody
});
}