Merge branch 'main' of https://github.com/ctwhome/portfolio #4
This file contains 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
name: ctw-kit | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'ctw-kit/**' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
release-and-publish: | |
runs-on: ubuntu-24.04 | |
if: ${{ github.event_name == 'workflow_dispatch' || (github.event.head_commit != null && !contains(github.event.head_commit.author.email, '[email protected]')) }} | |
defaults: | |
run: | |
working-directory: ctw-kit | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT_TOKEN }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20.x' | |
registry-url: 'https://registry.npmjs.org' | |
- name: Bump version | |
id: bump-version | |
run: | | |
npm version patch --no-git-tag-version | |
NEW_VERSION=$(node -p "require('./package.json').version") | |
PACKAGE_NAME=$(node -p "require('./package.json').name") | |
echo "new_version=${NEW_VERSION}" >> "$GITHUB_OUTPUT" | |
echo "name=${PACKAGE_NAME}" >> "$GITHUB_OUTPUT" | |
# Check if new version already exists | |
if npm view $PACKAGE_NAME@$NEW_VERSION version >/dev/null 2>&1; then | |
echo "Version $NEW_VERSION already exists in npm registry for package $PACKAGE_NAME" | |
exit 1 | |
fi | |
- name: Commit version bump | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add package.json | |
git commit -m "chore: bump version to ${{ steps.bump-version.outputs.new_version }}" | |
git push origin HEAD:main | |
- name: Create Git tag | |
run: | | |
if [ -z "$(git tag -l '${{ steps.bump-version.outputs.new_version }}')" ]; then | |
git tag ${{ steps.bump-version.outputs.new_version }} | |
git push origin ${{ steps.bump-version.outputs.new_version }} | |
else | |
echo "Tag ${{ steps.bump-version.outputs.new_version }} already exists" | |
exit 1 | |
fi | |
- name: Setup GitHub CLI | |
run: | | |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
&& sudo apt update \ | |
&& sudo apt install gh -y | |
- name: Create Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | |
run: | | |
gh release create ${{ steps.bump-version.outputs.new_version }} \ | |
--title "Release ${{ steps.bump-version.outputs.new_version }}" \ | |
--generate-notes | |
- uses: oven-sh/setup-bun@v1 | |
with: | |
bun-version: latest | |
- name: Install dependencies | |
run: bun install | |
- name: Build | |
run: bun run build | |
- name: Publish to npm | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: | | |
if ! npm publish --access public 2>&1 | grep -q "EOTP"; then | |
echo "Package published successfully" | |
else | |
echo "Error: npm requires 2FA. Please check your npm account settings:" | |
echo "1. Go to npmjs.com → Profile Settings → Authentication & Authorization" | |
echo "2. Under 'Two-Factor Authentication', ensure it's not set to 'Required for all operations'" | |
exit 1 | |
fi |