-
Notifications
You must be signed in to change notification settings - Fork 6
146 lines (132 loc) · 5.6 KB
/
Copy pathbuild-publish.yaml
File metadata and controls
146 lines (132 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
# Automatically build and publish
name: Build and Publish
# yamllint disable-line rule:truthy
on:
push:
tags: ['v[0-9]+**']
jobs:
sanity-check:
name: Sanity Check
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: Check tag is releasable
id: check_tag
run: |
TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref }})
ON_MAIN=$(git branch -r --contains $TAG_COMMIT | tr -d ' ' | grep -o '^origin/main$' || true)
IS_PRERELEASE=$(echo "${{ github.ref }}" | grep -oE 'v.*[^a-zA-Z][ab][0-9][0-9.-]*$' || true)
echo "on_main=$ON_MAIN" >> $GITHUB_OUTPUT
echo "is_prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT
echo "ok=${ON_MAIN}${IS_PRERELEASE}" >> $GITHUB_OUTPUT
- name: Fail if tag is not on main and not a prerelease version
if: steps.check_tag.outputs.ok == ''
run: |
echo "Tag is not on main and is not a prerelease version. Exiting."
exit 1
# Look for a passing run of the testing workflow already tied to this
# commit. Merges/pushes to main test the same SHA we tag, so full releases
# normally already have a passing run and can skip the inline tests below.
check-tests:
name: Check for existing test run
runs-on: ubuntu-22.04
needs: sanity-check
outputs:
already_tested: ${{ steps.check.outputs.already_tested }}
steps:
- name: Look for a passing test run for this commit
id: check
env:
GH_TOKEN: ${{ github.token }}
run: |
SHA="${{ github.sha }}"
SUCCESS=$(gh api \
"repos/${{ github.repository }}/actions/workflows/testing.yaml/runs?head_sha=$SHA&status=completed" \
--jq '[.workflow_runs[] | select(.conclusion == "success")] | length')
if [ "${SUCCESS:-0}" -gt 0 ]; then
echo "Found $SUCCESS passing test run(s) for $SHA; skipping inline tests."
echo "already_tested=true" >> "$GITHUB_OUTPUT"
else
echo "No passing test run for $SHA; tests will run inline."
echo "already_tested=false" >> "$GITHUB_OUTPUT"
fi
# Inline fallback: only runs when the tagged commit has no passing test
# run yet (e.g. prereleases cut from commits that were never on main).
run-tests:
name: Run tests (inline fallback)
needs: check-tests
if: needs.check-tests.outputs.already_tested != 'true'
uses: ./.github/workflows/testing.yaml
secrets: inherit
build-python:
name: Build & Publish
runs-on: ubuntu-22.04
env:
UV_PRERELEASE: allow
PIP_PRE: 1
permissions:
id-token: write
needs: [sanity-check, check-tests, run-tests]
# Proceed when tests are known good: either a pre-existing passing run
# (run-tests skipped) or a successful inline run. !failure() lets a
# skipped run-tests through while still blocking on any real failure.
if: ${{ !failure() && !cancelled() }}
steps:
- name: Apt update and build install
shell: bash
run: |
sudo apt update || true
sudo apt install -y nodejs npm python3-pip || true
pip install uv
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: make build
shell: bash
run: |
make build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
build-deploy-npm:
name: Build & Publish
runs-on: ubuntu-22.04
needs: [sanity-check, check-tests, run-tests]
# See build-python: proceed on a pre-existing pass or a successful
# inline run, block on any real failure.
if: ${{ !failure() && !cancelled() }}
permissions:
id-token: write
steps:
- uses: actions/setup-node@v6
with:
node-version: '24.x'
registry-url: 'https://registry.npmjs.org'
- name: Checkout
uses: actions/checkout@v5
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Check if prerelease
id: prerelease_tag
run: |
PRERELEASE_TAG=$(echo "${{ github.ref }}" | grep -oE 'v.*[^a-zA-Z][ab][0-9][0-9.-]*$' >/dev/null 2>/dev/null && echo " --tag next" || echo "" )
echo prerelease_tag=$PRERELEASE_TAG >> $GITHUB_OUTPUT
- name: npm build beaker-ts
working-directory: beaker-ts
shell: bash
run: |
npm i
npm run build
npm publish --provenance --access public ${{ steps.prerelease_tag.outputs.prerelease_tag }}
- name: npm build beaker-vue
working-directory: beaker-vue
shell: bash
run: |
npm i
npm run build
npm publish --provenance --access public ${{ steps.prerelease_tag.outputs.prerelease_tag }}