Skip to content

fix(ci): rename caller workflow to match pypi trusted publisher #12

fix(ci): rename caller workflow to match pypi trusted publisher

fix(ci): rename caller workflow to match pypi trusted publisher #12

Workflow file for this run

name: Semantic Release
on:
push:
branches:
- main
- dev
jobs:
test:
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Run import test
run: |
python -c "import hatch; print('Hatch package imports successfully')"
release:
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
needs: test
runs-on: ubuntu-latest
outputs:
published: ${{ steps.semantic_release.outputs.published }}
tag: ${{ steps.semantic_release.outputs.tag }}
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.SEMANTIC_RELEASE_APP_ID }}
private_key: ${{ secrets.SEMANTIC_RELEASE_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.generate_token.outputs.token }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: Install Node dependencies
run: npm ci
- name: Verify npm audit
run: npm audit signatures
- name: Release
id: semantic_release
env:
GITHUB_TOKEN: ${{ steps.generate_token.outputs.token }}
GH_TOKEN: ${{ steps.generate_token.outputs.token }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
node <<'EOF'
const fs = require('fs');
(async () => {
const semanticReleaseModule = await import('semantic-release');
const semanticRelease = semanticReleaseModule.default || semanticReleaseModule;
const result = await semanticRelease();
if (!process.env.GITHUB_OUTPUT) {
throw new Error('GITHUB_OUTPUT is not set');
}
if (!result) {
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'published=false\n');
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'tag=\n');
return;
}
fs.appendFileSync(process.env.GITHUB_OUTPUT, 'published=true\n');
fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${result.nextRelease.gitTag}\n`);
})().catch((error) => {
console.error(error);
process.exit(1);
});
EOF
publish:
name: Publish released package
needs: release
if: ${{ needs.release.outputs.published == 'true' }}
uses: ./.github/workflows/pypi-publish.yml
with:
tag: ${{ needs.release.outputs.tag }}
secrets: inherit
notify-discord:
name: Notify Discord
needs:
- release
- publish
if: ${{ needs.release.outputs.published == 'true' && needs.publish.result == 'success' }}
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Resolve GitHub release
id: release
uses: actions/github-script@v8
env:
TAG_NAME: ${{ needs.publish.outputs.tag }}
with:
script: |
const { data: release } = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: process.env.TAG_NAME,
});
core.setOutput('tag_name', release.tag_name);
core.setOutput('html_url', release.html_url);
core.setOutput('is_prerelease', String(release.prerelease));
- name: Build Discord payload
id: discord
uses: actions/github-script@v8
env:
TAG_NAME: ${{ steps.release.outputs.tag_name }}
HTML_URL: ${{ steps.release.outputs.html_url }}
IS_PRERELEASE: ${{ steps.release.outputs.is_prerelease }}
with:
script: |
const isPrerelease = process.env.IS_PRERELEASE === 'true';
const tagName = process.env.TAG_NAME;
const htmlUrl = process.env.HTML_URL;
core.setOutput('content', isPrerelease ? '' : '<@&1418053865818951721>');
core.setOutput('title', isPrerelease
? '🧪 Hatch Pre-release Available for Testing'
: '🎉 New *Hatch!* Release Available!');
core.setOutput('description', isPrerelease
? `**Version \`${tagName}\`** is now available for testing!\n\n⚠️ **This is a pre-release** - expect potential bugs and breaking changes\n🔬 Perfect for testing new features and providing feedback\n📋 Click [here](${htmlUrl}) to view what's new and download\n\n💻 Install with pip:\n\`\`\`bash\npip install hatch-xclam==${tagName}\n\`\`\`\n\nHelp us make *Hatch!* better by testing and reporting [issues](https://github.com/CrackingShells/Hatch/issues)! 🐛➡️✨`
: `**Version \`${tagName}\`** has been released!\n\n🚀 Get the latest features and improvements\n📚 Click [here](${htmlUrl}) to view the changelog and download\n\n💻 Install with pip:\n\`\`\`bash\npip install hatch-xclam\n\`\`\`\n\nHappy MCP coding with *Hatch!* 🐣`);
core.setOutput('color', isPrerelease ? '0xff9500' : '0x00ff88');
core.setOutput('username', isPrerelease
? 'Cracking Shells Pre-release Bot'
: 'Cracking Shells Release Bot');
core.setOutput('image', isPrerelease
? 'https://raw.githubusercontent.com/CrackingShells/.github/main/resources/images/hatch_icon_dark_bg_transparent.png'
: 'https://raw.githubusercontent.com/CrackingShells/.github/main/resources/images/hatch_icon_light_bg_transparent.png');
core.setOutput('avatar_url', isPrerelease
? 'https://raw.githubusercontent.com/CrackingShells/.github/main/resources/images/cs_core_dark_bg.png'
: 'https://raw.githubusercontent.com/CrackingShells/.github/main/resources/images/cs_icon_light_bg.png');
- name: Send Discord notification
uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_HATCH_ANNOUNCEMENTS }}
nodetail: true
content: ${{ steps.discord.outputs.content }}
title: ${{ steps.discord.outputs.title }}
description: ${{ steps.discord.outputs.description }}
color: ${{ steps.discord.outputs.color }}
username: ${{ steps.discord.outputs.username }}
image: ${{ steps.discord.outputs.image }}
avatar_url: ${{ steps.discord.outputs.avatar_url }}