changed publish.yml workflow

This commit is contained in:
2026-05-19 16:27:38 -05:00
parent 431e328909
commit a43364785c

View File

@@ -1,104 +1,80 @@
name: CI/CD Pipeline name: Publish Language Pack
on: on:
push: push:
branches: ["main"] tags:
tags: ["v*"] # Triggers production deployment whenever a version tag is pushed - "v*" # Fires directly on v0.1.0, v0.2.0 etc.
pull_request:
branches: ["main"]
jobs: jobs:
# --------------------------------------------------------------------------- # Enforce that tests MUST pass before release can execute
# Stage 1: Quality Control & Automated Verification verify:
# ---------------------------------------------------------------------------
test:
name: Verify Pack Integrity
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout Code - uses: actions/checkout@v4
uses: actions/checkout@v4 - name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install and Verify
run: |
pip install pytest
pytest tests/ -v
publish:
needs: verify # Blocks execution if verify job fails
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python - name: Set up Python
uses: actions/setup-python@v5 uses: actions/setup-python@v5
with: with:
python-version: "3.11" python-version: "3.11"
- name: Install Testing Environment - name: Install Release Tools
run: | run: pip install build twine
python -m pip install --upgrade pip
pip install pytest
- name: Execute Code Audit - name: Build Wheel and Source Distribution
run: python -m pytest tests/ -v # Automatically detects pyproject.toml and builds the correct pack
run: python -m build .
# ---------------------------------------------------------------------------
# Stage 2: Production Build & Multi-Platform Distribution
# ---------------------------------------------------------------------------
publish:
name: Production Release (PyPI & Gitea)
needs: test
if: startsWith(github.ref, 'refs/tags/v') # Strictly run only for tagged versions
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Production Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Modern Build Toolchain
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Compile Distribution Assets (PEP 517)
# This automatically handles whatever package name is configured inside pyproject.toml
run: python -m build
- name: Publish Package to PyPI - name: Publish Package to PyPI
env: env:
TWINE_USERNAME: __token__ TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} # Uses your org-level token safely # Inherits your clean Organization level secret
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload --skip-existing dist/* run: twine upload --skip-existing dist/*
- name: Generate Automated Gitea Release - name: Build Gitea Release with Assets
uses: actions/github-script@v7 env:
with: # Pulls your clean Organization level Gitea Token
script: | GIT_RELEASE_TOKEN: ${{ secrets.GIT_RELEASE_TOKEN }}
const fs = require('fs'); run: |
const path = require('path'); TAG=${GITHUB_REF#refs/tags/}
REPO_NAME=${{ github.event.repository.name }}
// Extract tag context # Delete existing release block if present
const tagName = context.ref.replace('refs/tags/', ''); EXISTING=$(curl -s -H "Authorization: token $GIT_RELEASE_TOKEN" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG")
EXISTING_ID=$(echo $EXISTING | python -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "")
if [ -n "$EXISTING_ID" ]; then
curl -s -X DELETE -H "Authorization: token $GIT_RELEASE_TOKEN" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$EXISTING_ID"
fi
// Create the Gitea Release container # Create fresh production release container
const release = await github.rest.repos.createRelease({ RELEASE=$(curl -s -X POST \
owner: context.repo.owner, -H "Authorization: token $GIT_RELEASE_TOKEN" \
repo: context.repo.repo, -H "Content-Type: application/json" \
tag_name: tagName, -d "{
name: `Release ${tagName}`, \"tag_name\": \"$TAG\",
body: `Automated distribution release for version ${tagName}. Verified by system tests.`, \"name\": \"$REPO_NAME $TAG\",
draft: false, \"body\": \"Language pack release version $TAG for the foreignthon transpiler framework.\",
prerelease: false \"draft\": false,
}); \"prerelease\": false
}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
// Read and attach compiled distribution files (.whl and .tar.gz) RELEASE_ID=$(echo $RELEASE | python -c "import sys,json; print(json.load(sys.stdin)['id'])")
const distDir = './dist';
const files = fs.readdirSync(distDir);
for (const file of files) { # Upload wheels directly into Gitea Assets tab
const filePath = path.join(distDir, file); for FILE in dist/*; do
const fileData = fs.readFileSync(filePath); curl -s -X POST -H "Authorization: token $GIT_RELEASE_TOKEN" -F "attachment=@$FILE" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets"
done
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id,
name: file,
data: fileData
});
console.log(`Successfully attached asset: ${file}`);
}