Skip to content

ci: fix of publish with latest or alpha tags based on ref_name #4

ci: fix of publish with latest or alpha tags based on ref_name

ci: fix of publish with latest or alpha tags based on ref_name #4

name: Refact Agent GUI CI Publish (Node.js)
on:
workflow_dispatch:
inputs:
perform_publish:
required: true
type: boolean
default: false
description: Publish to NPM Registry
# Automatic trigger for alpha and dev branches
push:
branches: [dev, test/workflow-alpha-version]
paths:
- 'refact-agent/gui/**'
- '.github/workflows/agent_gui_*'
pull_request:
paths:
- 'refact-agent/gui/**'
- '.github/workflows/agent_gui_*'
branches:
- 'test/workflow-alpha-version'
defaults:
run:
working-directory: refact-agent/gui
jobs:
publish:
runs-on: ubuntu-latest
# Runs only if pushing to dev or test/workflow-alpha-version, workflow_dispatch with inputs.perform_publish
# or on pull request trigger of test/workflow-alpha-version
if: |
inputs.perform_publish ||
(
github.event_name == 'push' &&
(
github.ref == 'refs/heads/dev' ||
github.ref == 'refs/heads/test/workflow-alpha-version'
)
) ||
(
github.event_name == 'pull_request' &&
github.head_ref == 'test/workflow-alpha-version'
)
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: refact-agent/gui/package-lock.json
- name: Install dependencies
run: |
npm pkg delete scripts.prepare
npm ci
- name: Configure Git
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Debug information
run: |
echo "github.event_name: ${{ github.event_name }}"
echo "github.ref: ${{ github.ref }}"
echo "inputs.ref_name: ${{ github.ref_name }}"
echo "inputs.head_ref: ${{ github.head_ref }}"
echo "inputs.perform_publish: ${{ inputs.perform_publish }}"
- name: Bump version
run: |
# Get current version from package.json
VERSION=$(node -p "require('./package.json').version")
echo "Current version: $VERSION"
# Determine version bump type based on branch/PR
if [[ "${{ github.ref }}" == "refs/heads/dev" ]] || \
[[ "${{ github.ref }}" == "refs/heads/test/workflow-alpha-version" ]] || \
[[ "${{ github.event_name }}" == "pull_request" && "${{ github.head_ref }}" == "test/workflow-alpha-version" ]] || \
[[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.ref }}" == "refs/heads/dev" ]]; then
echo "Bumping alpha version..."
npm run alpha:version
else
echo "Bumping patch version..."
npm version patch -m "Bump version to %s [skip ci]"
fi
# Show new version for debugging
NEW_VERSION=$(node -p "require('./package.json').version")
echo "New version: $NEW_VERSION"
- name: Publish to NPM Registry
run: |
# Get current version from package.json
VERSION=$(node -p "require('./package.json').version")
echo "Attempting to publish version: $VERSION"
# Check if version exists
if npm view refact-chat-js@$VERSION version &> /dev/null; then
echo "Version $VERSION already exists in npm registry!"
exit 1
else
echo "Version $VERSION is available, proceeding with publish..."
if [[ "${{ github.event_name }}" == "push" && ("${{ github.ref_name }}" == "dev" || "${{ github.ref_name }}" == "test/workflow-alpha-version") ]] || \
[[ "${{ github.event_name }}" == "pull_request" && "${{ github.head_ref }}" == "test/workflow-alpha-version" ]] || \
[[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.ref }}" == "refs/heads/dev" ]]; then
npm run alpha:publish
else
npm publish
fi
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Setup vars
shell: bash
id: setupvars
run: |
echo "plugin_version=$(node -p "require('./package.json').version")" >> "$GITHUB_OUTPUT"
- name: Commit and push version update
run: |
VERSION="${{ steps.setupvars.outputs.plugin_version }}"
git add package.json package-lock.json
git commit -m "Version bump $VERSION"
git push origin HEAD:${{ github.ref_name }}
# not sure if we have this set up
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "GUI ${{ steps.setupvars.outputs.plugin_version }} is published on npm registry",
"emoji": true
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "by ${{ github.actor }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK