diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..13f7b57 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,31 @@ +name: CD + +# Must select "Read and write permissions" in GitHub → Repo → Settings → Actions → General → Workflow permissions + + +on: + push: + branches: [ main, master ] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@master + with: + fetch-depth: 0 # To fetch all history for tags + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22' + + - name: Tag and release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} + ./scripts/release.sh \ No newline at end of file diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100644 index 0000000..82aee11 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Release script for release.yaml (a GitHub Action) +# Can be run locally as well if desired +# It creates a tag based on the version in pyproject.toml and creates a GitHub release based on the tag + +set -e +cd "$(dirname "$0")"/.. + +tag=$(node -p "require('./package.json').version") + +tagged=$(git tag -l $tag) +if [ -z "$tagged" ]; then + git tag -a "$tag" -m "Release $tag" + git push origin "$tag" + echo "Tagged release $tag" + + gh release create "$tag" \ + --repo="$GITHUB_REPOSITORY" \ + --title="$tag" \ + --generate-notes + echo "Created release" + +# Release to ... + +else + echo "Tag $tag already exists" +fi