forked from PostHog/posthog
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (119 loc) · 5.81 KB
/
build-hogql-parser.yml
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
name: Release hogql-parser
on:
pull_request:
paths:
- common/hogql_parser/**
- .github/workflows/build-hogql-parser.yml
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
check-version:
name: Check version legitimacy
runs-on: ubuntu-22.04
outputs:
parser-release-needed: ${{ steps.version.outputs.parser-release-needed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetching all for comparison since last push (not just last commit)
- name: Check if common/hogql_parser/ has changed
id: changed-files
uses: tj-actions/changed-files@v43
with:
since_last_remote_commit: true
files_yaml: |
parser:
- common/hogql_parser/**
- name: Check if version was bumped
shell: bash
id: version
run: |
parser_release_needed='false'
if [[ ${{ steps.changed-files.outputs.parser_any_changed }} == 'true' ]]; then
published=$(curl -fSsl https://pypi.org/pypi/hogql-parser/json | jq -r '.info.version')
local=$(python common/hogql_parser/setup.py --version)
if [[ "$published" != "$local" ]]; then
parser_release_needed='true'
else
message_body="It looks like the code of \`hogql-parser\` has changed since last push, but its version stayed the same at $local. 👀\nMake sure to resolve this in \`hogql_parser/setup.py\` before merging!${{ github.event.pull_request.head.repo.full_name != 'PostHog/posthog' && '\nThis needs to be performed on a branch created on the PostHog/posthog repo itself. A PostHog team member will assist with this.' || ''}}"
curl -s -u posthog-bot:${{ secrets.POSTHOG_BOT_GITHUB_TOKEN || secrets.GITHUB_TOKEN }} -X POST -d "{ \"body\": \"$message_body\" }" "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
fi
fi
echo "parser-release-needed=$parser_release_needed" >> $GITHUB_OUTPUT
build-wheels:
name: Build wheels on ${{ matrix.os }}
needs: check-version
runs-on: ${{ matrix.os }}
timeout-minutes: 30
if: needs.check-version.outputs.parser-release-needed == 'true' &&
github.event.pull_request.head.repo.full_name == 'PostHog/posthog'
strategy:
matrix:
# As of October 2023, GitHub doesn't have ARM Actions runners… and ARM emulation is insanely slow
# (20x longer) on the Linux runners (while being reasonable on the macOS runners). Hence, we use
# BuildJet as a provider of ARM runners - this solution saves a lot of time and consequently some money.
os: [ubuntu-22.04, buildjet-2vcpu-ubuntu-2204-arm, macos-13]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Build sdist
if: matrix.os == 'ubuntu-22.04' # Only build the sdist once
run: cd common/hogql_parser && python setup.py sdist
- name: Install cibuildwheel
run: pip install cibuildwheel==2.16.*
- name: Build wheels
run: cd common/hogql_parser && python -m cibuildwheel --output-dir dist
env:
MACOSX_DEPLOYMENT_TARGET: '13' # A modern target allows us to use C++20
- name: Upload wheels artifact
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.os }}
path: |
common/hogql_parser/dist/*.whl
common/hogql_parser/dist/*.tar.gz
if-no-files-found: error
publish:
name: Publish on PyPI
needs: build-wheels
environment: pypi-hogql-parser
permissions:
id-token: write
runs-on: ubuntu-22.04
steps:
- name: Download wheels from ubuntu-22.04
uses: actions/download-artifact@v4
with:
name: wheels-ubuntu-22.04
path: dist
- name: Download wheels from buildjet-2vcpu-ubuntu-2204-arm
uses: actions/download-artifact@v4
with:
name: wheels-buildjet-2vcpu-ubuntu-2204-arm
path: dist
- name: Download wheels from macos-13
uses: actions/download-artifact@v4
with:
name: wheels-macos-13
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- uses: actions/checkout@v4
with:
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Update hogql-parser in requirements
shell: bash
run: |
local=$(python common/hogql_parser/setup.py --version)
sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.in
sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.txt
- uses: EndBug/add-and-commit@v9
with:
add: '["requirements.in", "requirements.txt"]'
message: 'Use new hogql-parser version'
default_author: github_actions
github_token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}