|
1 |
| -name: Release |
| 1 | +name: Automatic Release Creation |
2 | 2 |
|
3 | 3 | on:
|
4 |
| - schedule: |
5 |
| - # Run every day at 9:00 UTC |
6 |
| - - cron: '0 9 * * *' |
7 |
| - # Allow manual trigger for testing |
8 | 4 | workflow_dispatch:
|
| 5 | + schedule: |
| 6 | + - cron: '0 10 * * *' |
9 | 7 |
|
10 | 8 | jobs:
|
11 |
| - prepare: |
| 9 | + create-metadata: |
12 | 10 | runs-on: ubuntu-latest
|
13 | 11 | outputs:
|
14 |
| - matrix: ${{ steps.set-matrix.outputs.matrix }} |
15 |
| - last_release: ${{ steps.last-release.outputs.hash }} |
| 12 | + hash: ${{ steps.last-release.outputs.hash }} |
| 13 | + version: ${{ steps.create-version.outputs.version}} |
| 14 | + npm_packages: ${{ steps.create-npm-packages.outputs.npm_packages}} |
| 15 | + pypi_packages: ${{ steps.create-pypi-packages.outputs.pypi_packages}} |
16 | 16 | steps:
|
17 | 17 | - uses: actions/checkout@v4
|
18 | 18 | with:
|
19 | 19 | fetch-depth: 0
|
20 | 20 |
|
21 |
| - - name: Find package directories |
22 |
| - id: set-matrix |
23 |
| - run: | |
24 |
| - DIRS=$(git ls-tree -r HEAD --name-only | grep -E "package.json|pyproject.toml" | xargs dirname | grep -v "^.$" | jq -R -s -c 'split("\n")[:-1]') |
25 |
| - echo "matrix=${DIRS}" >> $GITHUB_OUTPUT |
26 |
| -
|
27 | 21 | - name: Get last release hash
|
28 | 22 | id: last-release
|
29 | 23 | run: |
|
30 | 24 | HASH=$(git rev-list --tags --max-count=1 || echo "HEAD~1")
|
31 | 25 | echo "hash=${HASH}" >> $GITHUB_OUTPUT
|
| 26 | + echo "Using last release hash: ${HASH}" |
32 | 27 |
|
33 |
| - release: |
34 |
| - needs: prepare |
| 28 | + - name: Install uv |
| 29 | + uses: astral-sh/setup-uv@v5 |
| 30 | + |
| 31 | + - name: Create version name |
| 32 | + id: create-version |
| 33 | + run: | |
| 34 | + VERSION=$(uv run --script scripts/release.py generate-version) |
| 35 | + echo "version $VERSION" |
| 36 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Create notes |
| 39 | + run: | |
| 40 | + HASH="${{ steps.last-release.outputs.hash }}" |
| 41 | + uv run --script scripts/release.py generate-notes --directory src/ $HASH > RELEASE_NOTES.md |
| 42 | + cat RELEASE_NOTES.md |
| 43 | +
|
| 44 | + - name: Release notes |
| 45 | + uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: release-notes |
| 48 | + path: RELEASE_NOTES.md |
| 49 | + |
| 50 | + - name: Create python matrix |
| 51 | + id: create-pypi-packages |
| 52 | + run: | |
| 53 | + HASH="${{ steps.last-release.outputs.hash }}" |
| 54 | + PYPI=$(uv run --script scripts/release.py generate-matrix --pypi --directory src $HASH) |
| 55 | + echo "pypi_packages $PYPI" |
| 56 | + echo "pypi_packages=$PYPI" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: Create npm matrix |
| 59 | + id: create-npm-packages |
| 60 | + run: | |
| 61 | + HASH="${{ steps.last-release.outputs.hash }}" |
| 62 | + NPM=$(uv run --script scripts/release.py generate-matrix --npm --directory src $HASH) |
| 63 | + echo "npm_packages $NPM" |
| 64 | + echo "npm_packages=$NPM" >> $GITHUB_OUTPUT |
| 65 | +
|
| 66 | + update-packages: |
| 67 | + needs: [create-metadata] |
| 68 | + if: ${{ needs.create-metadata.outputs.npm_packages != '[]' || needs.create-metadata.outputs.pypi_packages != '[]' }} |
35 | 69 | runs-on: ubuntu-latest
|
| 70 | + outputs: |
| 71 | + changes_made: ${{ steps.commit.outputs.changes_made }} |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + fetch-depth: 0 |
| 76 | + |
| 77 | + - name: Install uv |
| 78 | + uses: astral-sh/setup-uv@v5 |
| 79 | + |
| 80 | + - name: Update packages |
| 81 | + run: | |
| 82 | + HASH="${{ needs.create-metadata.outputs.hash }}" |
| 83 | + uv run --script scripts/release.py update-packages --directory src/ $HASH |
| 84 | +
|
| 85 | + - name: Configure git |
| 86 | + run: | |
| 87 | + git config --global user.name "GitHub Actions" |
| 88 | + git config --global user.email "[email protected]" |
| 89 | +
|
| 90 | + - name: Commit changes |
| 91 | + id: commit |
| 92 | + run: | |
| 93 | + VERSION="${{ needs.create-metadata.outputs.version }}" |
| 94 | + git add -u |
| 95 | + if git diff-index --quiet HEAD; then |
| 96 | + echo "changes_made=false" >> $GITHUB_OUTPUT |
| 97 | + else |
| 98 | + git commit -m 'Automatic update of packages' |
| 99 | + git tag -a "$VERSION" -m "Release $VERSION" |
| 100 | + git push origin "$VERSION" |
| 101 | + echo "changes_made=true" >> $GITHUB_OUTPUT |
| 102 | + fi |
| 103 | +
|
| 104 | + publish-pypi: |
| 105 | + needs: [update-packages, create-metadata] |
36 | 106 | strategy:
|
37 |
| - matrix: |
38 |
| - directory: ${{ fromJson(needs.prepare.outputs.matrix) }} |
39 | 107 | fail-fast: false
|
| 108 | + matrix: |
| 109 | + package: ${{ fromJson(needs.create-metadata.outputs.pypi_packages) }} |
| 110 | + name: Build ${{ matrix.package }} |
| 111 | + environment: release |
40 | 112 | permissions:
|
41 |
| - contents: write |
42 |
| - packages: write |
43 |
| - |
| 113 | + id-token: write # Required for trusted publishing |
| 114 | + runs-on: ubuntu-latest |
44 | 115 | steps:
|
45 | 116 | - uses: actions/checkout@v4
|
46 | 117 | with:
|
47 |
| - fetch-depth: 0 |
| 118 | + ref: ${{ needs.create-metadata.outputs.version }} |
| 119 | + |
| 120 | + - name: Install uv |
| 121 | + uses: astral-sh/setup-uv@v5 |
| 122 | + |
| 123 | + - name: Set up Python |
| 124 | + uses: actions/setup-python@v5 |
| 125 | + with: |
| 126 | + python-version-file: "src/${{ matrix.package }}/.python-version" |
| 127 | + |
| 128 | + - name: Install dependencies |
| 129 | + working-directory: src/${{ matrix.package }} |
| 130 | + run: uv sync --frozen --all-extras --dev |
| 131 | + |
| 132 | + - name: Run pyright |
| 133 | + working-directory: src/${{ matrix.package }} |
| 134 | + run: uv run --frozen pyright |
| 135 | + |
| 136 | + - name: Build package |
| 137 | + working-directory: src/${{ matrix.package }} |
| 138 | + run: uv build |
48 | 139 |
|
49 |
| - - uses: astral-sh/setup-uv@v5 |
| 140 | + - name: Publish package to PyPI |
| 141 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 142 | + with: |
| 143 | + packages-dir: src/${{ matrix.package }}/dist |
| 144 | + |
| 145 | + publish-npm: |
| 146 | + needs: [update-packages, create-metadata] |
| 147 | + strategy: |
| 148 | + fail-fast: false |
| 149 | + matrix: |
| 150 | + package: ${{ fromJson(needs.create-metadata.outputs.npm_packages) }} |
| 151 | + name: Build ${{ matrix.package }} |
| 152 | + environment: release |
| 153 | + runs-on: ubuntu-latest |
| 154 | + steps: |
| 155 | + - uses: actions/checkout@v4 |
| 156 | + with: |
| 157 | + ref: ${{ needs.create-metadata.outputs.version }} |
50 | 158 |
|
51 |
| - - name: Setup Node.js |
52 |
| - if: endsWith(matrix.directory, 'package.json') |
53 |
| - uses: actions/setup-node@v4 |
| 159 | + - uses: actions/setup-node@v4 |
54 | 160 | with:
|
55 |
| - node-version: '18' |
| 161 | + node-version: 22 |
| 162 | + cache: npm |
56 | 163 | registry-url: 'https://registry.npmjs.org'
|
57 | 164 |
|
58 |
| - - name: Setup Python |
59 |
| - if: endsWith(matrix.directory, 'pyproject.toml') |
60 |
| - run: uv python install |
| 165 | + - name: Install dependencies |
| 166 | + working-directory: src/${{ matrix.package }} |
| 167 | + run: npm ci |
| 168 | + |
| 169 | + - name: Check if version exists on npm |
| 170 | + working-directory: src/${{ matrix.package }} |
| 171 | + run: | |
| 172 | + VERSION=$(jq -r .version package.json) |
| 173 | + if npm view --json | jq --arg version "$VERSION" '[.[]][0].versions | contains([$version])'; then |
| 174 | + echo "Version $VERSION already exists on npm" |
| 175 | + exit 1 |
| 176 | + fi |
| 177 | + echo "Version $VERSION is new, proceeding with publish" |
61 | 178 |
|
62 |
| - - name: Release package |
| 179 | + - name: Build package |
| 180 | + working-directory: src/${{ matrix.package }} |
| 181 | + run: npm run build |
| 182 | + |
| 183 | + - name: Publish package |
| 184 | + working-directory: src/${{ matrix.package }} |
| 185 | + run: | |
| 186 | + npm publish --access public |
63 | 187 | env:
|
64 | 188 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
65 |
| - UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }} |
66 |
| - run: uv run --script scripts/release.py "${{ matrix.directory }}" "${{ needs.prepare.outputs.last_release }}" >> "$GITHUB_OUTPUT" |
67 | 189 |
|
68 | 190 | create-release:
|
69 |
| - needs: [prepare, release] |
| 191 | + needs: [update-packages, create-metadata, publish-pypi, publish-npm] |
| 192 | + if: needs.update-packages.outputs.changes_made == 'true' |
70 | 193 | runs-on: ubuntu-latest
|
| 194 | + environment: release |
71 | 195 | permissions:
|
72 | 196 | contents: write
|
73 | 197 | steps:
|
74 | 198 | - uses: actions/checkout@v4
|
75 | 199 |
|
76 |
| - - name: Create Release |
| 200 | + - name: Download release notes |
| 201 | + uses: actions/download-artifact@v4 |
| 202 | + with: |
| 203 | + name: release-notes |
| 204 | + |
| 205 | + - name: Create release |
77 | 206 | env:
|
78 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 207 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN}} |
79 | 208 | run: |
|
80 |
| - # Check if there's output from release step |
81 |
| - if [ -s "$GITHUB_OUTPUT" ]; then |
82 |
| - DATE=$(date +%Y.%m.%d) |
83 |
| -
|
84 |
| - # Create git tag |
85 |
| - git tag -s -a -m"automated release v${DATE}" "v${DATE}" |
86 |
| - git push origin "v${DATE}" |
87 |
| -
|
88 |
| - # Create release notes |
89 |
| - echo "# Release ${DATE}" > notes.md |
90 |
| - echo "" >> notes.md |
91 |
| - echo "## Updated Packages" >> notes.md |
92 |
| -
|
93 |
| - # Read updated packages from github output |
94 |
| - while IFS= read -r line; do |
95 |
| - echo "- ${line}" >> notes.md |
96 |
| - done < "$GITHUB_OUTPUT" |
97 |
| -
|
98 |
| - # Create GitHub release |
99 |
| - gh release create "v${DATE}" \ |
100 |
| - --title "Release ${DATE}" \ |
101 |
| - --notes-file notes.md |
102 |
| - fi |
| 209 | + VERSION="${{ needs.create-metadata.outputs.version }}" |
| 210 | + gh release create "$VERSION" \ |
| 211 | + --title "Release $VERSION" \ |
| 212 | + --notes-file RELEASE_NOTES.md |
0 commit comments