diff --git a/.github/workflows/publish-agentflow.yml b/.github/workflows/publish-agentflow.yml new file mode 100644 index 00000000000..829e49dce93 --- /dev/null +++ b/.github/workflows/publish-agentflow.yml @@ -0,0 +1,152 @@ +name: Publish @flowiseai/agentflow +on: + workflow_dispatch: + inputs: + bump: + description: 'Version bump type' + required: true + type: choice + default: 'prerelease' + options: + - prerelease + - patch + - minor + - major + - custom + custom_version: + description: 'Custom version (only used when bump is "custom", e.g. 1.0.0-beta.1)' + required: false + type: string + tag: + description: 'npm dist-tag' + required: false + type: choice + default: 'dev' + options: + - dev + - latest + +jobs: + dry-run: + runs-on: ubuntu-latest + permissions: + contents: read + outputs: + version: ${{ steps.resolve-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v2 + with: + version: 10.26.0 + + - uses: actions/setup-node@v4 + with: + node-version: '18.15.0' + registry-url: 'https://registry.npmjs.org' + + - name: Validate custom version + if: inputs.bump == 'custom' + run: | + if [ -z "$CUSTOM_VERSION" ]; then + echo "::error::custom_version is required when bump is 'custom'" + exit 1 + fi + npx semver "$CUSTOM_VERSION" || (echo "::error::Invalid semver: $CUSTOM_VERSION" && exit 1) + env: + CUSTOM_VERSION: ${{ inputs.custom_version }} + + - name: Install dependencies + run: pnpm install --frozen-lockfile + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + + - name: Set version + run: | + if [ "$BUMP" = "custom" ]; then + pnpm --filter @flowiseai/agentflow exec npm version "$CUSTOM_VERSION" --no-git-tag-version + else + pnpm --filter @flowiseai/agentflow exec npm version "$BUMP" --preid dev --no-git-tag-version + fi + env: + BUMP: ${{ inputs.bump }} + CUSTOM_VERSION: ${{ inputs.custom_version }} + + - name: Resolve version + id: resolve-version + run: | + VERSION=$(node -p "require('./packages/agentflow/package.json').version") + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "## Version to publish: \`$VERSION\`" >> "$GITHUB_STEP_SUMMARY" + echo "## Tag: \`${{ inputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY" + + - name: Package contents + run: pnpm --filter @flowiseai/agentflow exec npm pack --dry-run + + - name: Dry run publish + run: pnpm --filter @flowiseai/agentflow publish --no-git-checks --dry-run --tag ${{ inputs.tag }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + publish: + needs: dry-run + runs-on: ubuntu-latest + environment: npm-publish + permissions: + contents: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v2 + with: + version: 10.26.0 + + - uses: actions/setup-node@v4 + with: + node-version: '18.15.0' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: pnpm install --frozen-lockfile + env: + PUPPETEER_SKIP_DOWNLOAD: 'true' + + - name: Set version + run: | + if [ "$BUMP" = "custom" ]; then + pnpm --filter @flowiseai/agentflow exec npm version "$CUSTOM_VERSION" --no-git-tag-version + else + pnpm --filter @flowiseai/agentflow exec npm version "$BUMP" --preid dev --no-git-tag-version + fi + env: + BUMP: ${{ inputs.bump }} + CUSTOM_VERSION: ${{ inputs.custom_version }} + + - name: Log version + run: | + echo "Publishing version: ${{ needs.dry-run.outputs.version }}" + echo "Tag: ${{ inputs.tag }}" + + - name: Publish + run: pnpm --filter @flowiseai/agentflow publish --no-git-checks --tag ${{ inputs.tag }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Create version bump PR + run: | + VERSION="${{ needs.dry-run.outputs.version }}" + BRANCH="chore/bump-agentflow-${VERSION}" + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git checkout -b "$BRANCH" + git add packages/agentflow/package.json + git commit -m "chore: bump @flowiseai/agentflow to ${VERSION}" + git push -u origin "$BRANCH" + gh pr create \ + --title "chore: bump @flowiseai/agentflow to ${VERSION}" \ + --body "Automated version bump after publishing \`@flowiseai/agentflow@${VERSION}\` to npm with tag \`${{ inputs.tag }}\`." \ + --base main \ + --head "$BRANCH" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}