Skip to content

Commit 7a4b410

Browse files
authored
fix: add missing permissions to release workflow (#221)
1 parent ae157f2 commit 7a4b410

File tree

18 files changed

+2179
-36
lines changed

18 files changed

+2179
-36
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
((github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository) || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, vars.RELEASE_PR_BRANCH || 'create-pull-request'))) ||
5858
(github.repository == 'darvid/python-hyperscan' && contains(github.event.head_commit.message, '[build]'))
5959
run: |
60-
echo "valid_event=true" >> $GITHUB_OUTPUT
60+
echo "valid_event=true" >> "$GITHUB_OUTPUT"
6161
6262
check_changes:
6363
name: Build pre-conditions check
@@ -76,36 +76,37 @@ jobs:
7676

7777
- name: Check if build is needed
7878
id: check
79+
env:
80+
PR_TITLE: ${{ github.event.pull_request.title }}
7981
run: |
8082
if [[ "${{ inputs.force_build || false }}" == "true" ]]; then
81-
echo "should_build=true" >> $GITHUB_OUTPUT
83+
echo "should_build=true" >> "$GITHUB_OUTPUT"
8284
echo "Running build because force_build is true"
8385
exit 0
8486
fi
8587
8688
# Check for [build] tag in commit messages or PR title
8789
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
8890
# For PRs, check if PR title contains [build]
89-
PR_TITLE="${{ github.event.pull_request.title }}"
9091
if [[ "$PR_TITLE" == *"[build]"* ]]; then
91-
echo "should_build=true" >> $GITHUB_OUTPUT
92+
echo "should_build=true" >> "$GITHUB_OUTPUT"
9293
echo "Running build because PR title contains [build]"
9394
exit 0
9495
fi
9596
9697
# Also check all commits in the PR for [build]
9798
BASE_SHA="${{ github.event.pull_request.base.sha }}"
9899
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
99-
COMMIT_MSGS=$(git fetch origin $BASE_SHA $HEAD_SHA && git log --format=%B $BASE_SHA..$HEAD_SHA || echo "")
100+
COMMIT_MSGS=$(git fetch origin "$BASE_SHA" "$HEAD_SHA" && git log --format=%B "${BASE_SHA}..${HEAD_SHA}" || echo "")
100101
if echo "$COMMIT_MSGS" | grep -q "\[build\]"; then
101-
echo "should_build=true" >> $GITHUB_OUTPUT
102+
echo "should_build=true" >> "$GITHUB_OUTPUT"
102103
echo "Running build because a commit in the PR contains [build]"
103104
exit 0
104105
fi
105106
else
106107
# For pushes, check if the head commit message contains [build]
107108
if [[ "${{ contains(github.event.head_commit.message, '[build]') }}" == "true" ]]; then
108-
echo "should_build=true" >> $GITHUB_OUTPUT
109+
echo "should_build=true" >> "$GITHUB_OUTPUT"
109110
echo "Running build because commit message contains [build]"
110111
exit 0
111112
fi
@@ -115,7 +116,7 @@ jobs:
115116
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
116117
BASE_SHA="${{ github.event.pull_request.base.sha }}"
117118
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
118-
CHANGED_FILES=$(git fetch origin $BASE_SHA $HEAD_SHA && git diff --name-only $BASE_SHA $HEAD_SHA || echo "")
119+
CHANGED_FILES=$(git fetch origin "$BASE_SHA" "$HEAD_SHA" && git diff --name-only "${BASE_SHA}" "${HEAD_SHA}" || echo "")
119120
else
120121
# For pushes, use the before/after SHAs or fallback to comparing with parent
121122
BEFORE_SHA="${{ github.event.before }}"
@@ -126,12 +127,12 @@ jobs:
126127
CHANGED_FILES=$(git diff --name-only HEAD^ || echo "")
127128
else
128129
# Try to fetch the commits first to make sure they exist
129-
git fetch --depth=1 origin $BEFORE_SHA || true
130-
git fetch --depth=1 origin $AFTER_SHA || true
130+
git fetch --depth=1 origin "${BEFORE_SHA}" || true
131+
git fetch --depth=1 origin "${AFTER_SHA}" || true
131132
132133
# Check if both SHAs exist in the repository
133-
if git cat-file -e $BEFORE_SHA 2>/dev/null && git cat-file -e $AFTER_SHA 2>/dev/null; then
134-
CHANGED_FILES=$(git diff --name-only $BEFORE_SHA $AFTER_SHA || echo "")
134+
if git cat-file -e "${BEFORE_SHA}" 2>/dev/null && git cat-file -e "${AFTER_SHA}" 2>/dev/null; then
135+
CHANGED_FILES=$(git diff --name-only "${BEFORE_SHA}" "${AFTER_SHA}" || echo "")
135136
else
136137
# Fallback to comparing with parent commit
137138
echo "Cannot find one of the SHAs, falling back to HEAD^"
@@ -144,16 +145,16 @@ jobs:
144145
RESULT=1
145146
echo "$CHANGED_FILES" | grep -q -E '^(src/hyperscan/|README.md|CMakeLists.txt|pyproject.toml|MANIFEST.in|cmake/|build_tools/)' || RESULT=$?
146147
147-
if [[ $RESULT -eq 0 ]]; then
148-
echo "should_build=true" >> $GITHUB_OUTPUT
148+
if [[ "$RESULT" -eq 0 ]]; then
149+
echo "should_build=true" >> "$GITHUB_OUTPUT"
149150
echo "Running build because relevant files were changed"
150151
else
151-
echo "should_build=false" >> $GITHUB_OUTPUT
152+
echo "should_build=false" >> "$GITHUB_OUTPUT"
152153
echo "Skipping build because no relevant files were changed and commit doesn't have [build] tag"
153154
fi
154155
else
155156
# For pull requests, always build (after checking for [build] tag above)
156-
echo "should_build=true" >> $GITHUB_OUTPUT
157+
echo "should_build=true" >> "$GITHUB_OUTPUT"
157158
echo "Running build for pull request"
158159
fi
159160

.github/workflows/lint.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ jobs:
5454
src: "./src"
5555
args: check --fix
5656

57+
- name: Validate GitHub workflows
58+
uses: raven-actions/actionlint@v2
59+
5760
- name: Debug refs
61+
env:
62+
GITHUB_HEAD_REF: ${{ github.head_ref }}
63+
GITHUB_REF: ${{ github.ref }}
64+
GITHUB_SHA: ${{ github.sha }}
5865
run: |
59-
echo "github.ref: ${{ github.ref }}"
60-
echo "github.head_ref: ${{ github.head_ref }}"
61-
echo "github.sha: ${{ github.sha }}"
66+
echo "github.ref: ${GITHUB_REF}"
67+
echo "github.head_ref: ${GITHUB_HEAD_REF}"
68+
echo "github.sha: ${GITHUB_SHA}"
6269
6370
- name: Commit formatting changes
6471
uses: iarekylew00t/verified-bot-commit@v1

.github/workflows/publish.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
build:
1212
name: Build source distribution and wheels
1313
uses: ./.github/workflows/build.yml
14-
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, ${{ vars.RELEASE_PR_BRANCH || 'create-pull-request' }}) && github.repository == 'darvid/python-hyperscan'
14+
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, vars.RELEASE_PR_BRANCH || 'create-pull-request') && github.repository == 'darvid/python-hyperscan'
1515
permissions:
1616
contents: read
1717
actions: write
@@ -49,23 +49,23 @@ jobs:
4949
# Check if HEAD already has a release version tag (prevents redundant releases)
5050
if git describe --exact-match --tags HEAD --match "v*" 2>/dev/null; then
5151
EXISTING_TAG=$(git describe --exact-match --tags HEAD --match "v*" 2>/dev/null)
52-
echo "HEAD already tagged with release version $EXISTING_TAG, no release needed"
53-
echo "should_release=false" >> $GITHUB_OUTPUT
52+
echo "HEAD already tagged with release version ${EXISTING_TAG}, no release needed"
53+
echo "should_release=false" >> "$GITHUB_OUTPUT"
5454
else
5555
# Check if there are commits since last release
5656
LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "")
5757
if [[ -n "$LATEST_TAG" ]]; then
58-
COMMITS_COUNT=$(git rev-list ${LATEST_TAG}..HEAD --count 2>/dev/null || echo "1")
58+
COMMITS_COUNT=$(git rev-list "${LATEST_TAG}"..HEAD --count 2>/dev/null || echo "1")
5959
if [[ "$COMMITS_COUNT" -eq 0 ]]; then
60-
echo "No commits since last release $LATEST_TAG, no new content to release"
61-
echo "should_release=false" >> $GITHUB_OUTPUT
60+
echo "No commits since last release ${LATEST_TAG}, no new content to release"
61+
echo "should_release=false" >> "$GITHUB_OUTPUT"
6262
else
63-
echo "Found $COMMITS_COUNT commits since $LATEST_TAG, proceeding with release"
64-
echo "should_release=true" >> $GITHUB_OUTPUT
63+
echo "Found ${COMMITS_COUNT} commits since ${LATEST_TAG}, proceeding with release"
64+
echo "should_release=true" >> "$GITHUB_OUTPUT"
6565
fi
6666
else
6767
echo "No previous release found, proceeding with initial release"
68-
echo "should_release=true" >> $GITHUB_OUTPUT
68+
echo "should_release=true" >> "$GITHUB_OUTPUT"
6969
fi
7070
fi
7171

.github/workflows/release.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ jobs:
3535
CHANGED_FILES=""
3636
fi
3737
echo "Changed files:"
38-
echo "$CHANGED_FILES"
38+
echo "${CHANGED_FILES}"
3939
4040
CHANGES=0
41-
echo "$CHANGED_FILES" | grep -c -E '^(src/hyperscan/|README.md|CMakeLists.txt|pyproject.toml|MANIFEST.in|cmake/|build_tools/)' || CHANGES=$?
41+
echo "${CHANGED_FILES}" | grep -c -E '^(src/hyperscan/|README.md|CMakeLists.txt|pyproject.toml|MANIFEST.in|cmake/|build_tools/)' || CHANGES=$?
4242
4343
if [[ "$CHANGES" -gt 0 ]]; then
4444
# The last commit already triggered a build, no need to force
45-
echo "force_build=false" >> $GITHUB_OUTPUT
45+
echo "force_build=false" >> "$GITHUB_OUTPUT"
4646
echo "Last commit already triggered a build"
4747
else
4848
# The last commit didn't trigger a build, we need to force it
49-
echo "force_build=true" >> $GITHUB_OUTPUT
49+
echo "force_build=true" >> "$GITHUB_OUTPUT"
5050
echo "Last commit didn't trigger a build, forcing build"
5151
fi
5252
@@ -79,6 +79,9 @@ jobs:
7979
needs: [check_build, check_release]
8080
if: github.repository == 'darvid/python-hyperscan' && !contains(github.event.head_commit.message, 'python-semantic-release') && (needs.check_build.outputs.is_build_needed == 'true' || needs.check_release.outputs.is_release_needed == 'true')
8181
uses: ./.github/workflows/build.yml
82+
permissions:
83+
contents: read
84+
actions: write
8285
with:
8386
force_build: "${{ needs.check_release.outputs.is_release_needed == 'true' || fromJSON(needs.check_build.outputs.is_build_needed) }}"
8487

@@ -121,11 +124,11 @@ jobs:
121124
if: needs.check_release.outputs.is_release_needed == 'true'
122125
run: |
123126
# Check if branch exists on remote and delete it if it does
124-
if git ls-remote --heads origin ${RELEASE_PR_BRANCH} | grep -q ${RELEASE_PR_BRANCH}; then
125-
git push origin --delete ${RELEASE_PR_BRANCH}
127+
if git ls-remote --heads origin "${RELEASE_PR_BRANCH}" | grep -q "${RELEASE_PR_BRANCH}"; then
128+
git push origin --delete "${RELEASE_PR_BRANCH}"
126129
fi
127130
# Create new branch
128-
git switch -c ${RELEASE_PR_BRANCH}
131+
git switch -c "${RELEASE_PR_BRANCH}"
129132
130133
- name: Semantic release
131134
uses: python-semantic-release/python-semantic-release@v9.10.1
@@ -142,7 +145,7 @@ jobs:
142145
- name: Create PR
143146
if: needs.check_release.outputs.is_release_needed == 'true'
144147
run: |
145-
gh pr create -B main -H $RELEASE_PR_BRANCH \
148+
gh pr create -B main -H "$RELEASE_PR_BRANCH" \
146149
--title "$PR_TITLE" \
147150
--body '🤖'
148151
env:

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ repos:
1414
hooks:
1515
- id: commitizen
1616
stages: [commit-msg]
17+
- repo: https://github.com/rhysd/actionlint
18+
rev: v1.7.4
19+
hooks:
20+
- id: actionlint

actionlint

Whitespace-only changes.

test_issue_207.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
import hyperscan
4+
5+
print(f'hyperscan version: {hyperscan.__version__}')
6+
7+
# Exact code from GitHub issue #207
8+
bla = [r'<span\s+.*>السلام عليكم\s<\/span>'.encode('utf8'),
9+
r'<span\s+.*>ועליכום הסלאם\s<\/span>'.encode('utf8')]
10+
11+
print(f'Testing patterns: {bla}')
12+
13+
try:
14+
rules_db = hyperscan.Database()
15+
rules_db.compile(expressions=bla,
16+
flags=hyperscan.HS_FLAG_UTF8 | hyperscan.HS_FLAG_UCP)
17+
print('SUCCESS: Patterns compiled with HS_FLAG_UTF8 | HS_FLAG_UCP!')
18+
except Exception as e:
19+
print(f'FAILED: {e}')
20+
if 'Expression is not valid UTF-8' in str(e):
21+
print('*** THIS IS THE EXACT BUG FROM ISSUE #207! ***')
22+
else:
23+
print('*** Different error ***')

test_unicode.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python3
2+
3+
import hyperscan
4+
print(f'hyperscan version: {hyperscan.__version__}')
5+
6+
# Test unicode pattern compilation
7+
patterns = ['السلام عليكم', 'ועליכום הסלאם']
8+
print(f'Testing unicode patterns: {patterns}')
9+
10+
try:
11+
db = hyperscan.Database()
12+
db.compile(expressions=patterns)
13+
print('SUCCESS: Unicode patterns compiled without errors!')
14+
except Exception as e:
15+
print(f'FAILED: {str(e)}')
16+
if 'Expression is not valid UTF-8' in str(e):
17+
print('*** THIS IS THE BUG - the fix is NOT working! ***')
18+
else:
19+
print('*** Different error, not the unicode bug ***')
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Metadata-Version: 2.2
2+
Name: hyperscan
3+
Version: 0.7.19
4+
Summary: Python bindings for Hyperscan.
5+
Keywords: regex,hypercan
6+
Author-Email: David Gidwani <david.gidwani@atomweight.io>
7+
License: MIT
8+
Classifier: Development Status :: 4 - Beta
9+
Classifier: Topic :: Software Development :: Libraries
10+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
11+
Classifier: Topic :: Utilities
12+
Classifier: Programming Language :: Python
13+
Classifier: Programming Language :: Python :: 3
14+
Classifier: Programming Language :: Python :: 3.8
15+
Classifier: Programming Language :: Python :: 3.9
16+
Classifier: Programming Language :: Python :: 3.10
17+
Classifier: Programming Language :: Python :: 3.11
18+
Classifier: Programming Language :: Python :: 3.12
19+
Classifier: Programming Language :: Python :: 3.13
20+
Classifier: Programming Language :: Python :: Implementation :: CPython
21+
Classifier: Environment :: Console
22+
Classifier: Intended Audience :: Developers
23+
Classifier: License :: OSI Approved :: MIT License
24+
Classifier: Operating System :: POSIX :: Linux
25+
Classifier: Operating System :: Unix
26+
Classifier: Operating System :: MacOS
27+
Classifier: Operating System :: Microsoft :: Windows
28+
Project-URL: Homepage, https://github.com/darvid/python-hyperscan
29+
Project-URL: Repository, https://github.com/darvid/python-hyperscan
30+
Project-URL: Documentation, https://python-hyperscan.readthedocs.io/en/latest/
31+
Requires-Python: <4.0,>=3.9
32+
Description-Content-Type: text/markdown
33+
34+
# Hyperscan/Vectorscan for Python
35+
36+
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/darvid/python-hyperscan/build.yml?style=plastic)
37+
![PyPI - Version](https://img.shields.io/pypi/v/hyperscan?style=plastic)
38+
![PyPI - Downloads](https://img.shields.io/pypi/dm/hyperscan?style=plastic)
39+
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/hyperscan.svg?style=plastic)
40+
![PyPI - Wheel](https://img.shields.io/pypi/wheel/hyperscan.svg?style=plastic)
41+
![PyPI - License](https://img.shields.io/pypi/l/hyperscan.svg?style=plastic)
42+
[![Read the Docs](https://img.shields.io/readthedocs/python-hyperscan.svg?style=plastic)](https://python-hyperscan.readthedocs.io/en/latest/)
43+
44+
A CPython extension for [Vectorscan][7], an open source fork of
45+
[Hyperscan][8], Intel's open source ([prior to version 5.4][9]),
46+
high-performance multiple regex matching library.
47+
48+
* ✅ Binary [manylinux][12]-compatible wheels
49+
* ✅ Statically linked (no need to build Hyperscan/Vectorscan)
50+
* ✅ [Chimera][1] support
51+
52+
## Installation
53+
54+
```shell
55+
# 🪄 Installing libhs is NOT required, because python-hyperscan is statically linked
56+
pip install hyperscan
57+
```
58+
59+
## Build Optimization
60+
61+
If you'd like to use Intel's Hyperscan rather than Vectorscan, or if
62+
you'd like to enable native CPU detection to build optimized non-FAT
63+
libraries ([default off in Vectorscan][11]), extending the
64+
[manylinux-hyperscan][10] Docker image used to build the binary wheels
65+
for this library should be fairly straightforward.
66+
67+
## API Support
68+
69+
``python-hyperscan`` currently exposes *most* of the C API, with the
70+
following caveats or exceptions:
71+
72+
* No [stream compression][2] support.
73+
* No [custom allocator][3] support.
74+
* ``hs_expression_info``, ``hs_expression_ext_info``,
75+
``hs_populate_platform``, and ``hs_serialized_database_info`` not
76+
exposed yet.
77+
78+
See the [documentation][6] for more detailed build instructions.
79+
80+
## Resources
81+
82+
* [PyPI Project][13]
83+
* [Documentation][6]
84+
* [Hyperscan C API Documentation][14]
85+
86+
[1]: http://intel.github.io/hyperscan/dev-reference/chimera.html
87+
[2]: http://intel.github.io/hyperscan/dev-reference/runtime.html#stream-compression
88+
[3]: http://intel.github.io/hyperscan/dev-reference/runtime.html#custom-allocators
89+
[4]: http://intel.github.io/hyperscan/dev-reference/compilation.html
90+
[5]: https://github.com/darvid/python-hyperscan/issues
91+
[6]: https://python-hyperscan.readthedocs.io
92+
[7]: https://www.vectorcamp.gr/vectorscan/
93+
[8]: https://www.hyperscan.io/
94+
[9]: https://github.com/VectorCamp/vectorscan?tab=readme-ov-file#hyperscan-license-change-after-54
95+
[10]: https://github.com/darvid/manylinux-hyperscan/
96+
[11]: https://github.com/VectorCamp/vectorscan?tab=readme-ov-file#configure--build
97+
[12]: https://github.com/pypa/manylinux
98+
[13]: https://pypi.org/project/hyperscan/
99+
[14]: http://intel.github.io/hyperscan/dev-reference/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
hyperscan-0.7.19.dist-info/METADATA,sha256=6NsPEGGFUJdhx_ulIMD4Ff-cgw4FlNm1rgaFDQ7yI2Q,4299
2+
hyperscan-0.7.19.dist-info/RECORD,,
3+
hyperscan-0.7.19.dist-info/WHEEL,sha256=6Dxtid-NXEnR7jvm4_GvErwSb88e3UzL8AWq9MWuAAE,156
4+
hyperscan-0.7.19.dist-info/licenses/LICENSE,sha256=yvm4yRI_IxT-4iZOEl1Nx9I0Dm0JbAbmHt8OmKopiUA,1070
5+
hyperscan/__init__.py,sha256=ImBXLA9RN8dJIx94n6R3iRUOBO7v1-q8vImzzKPVLbU,367
6+
hyperscan/extension.c,sha256=xcYkpNIuIIYNGFWKC46lp9YYbOABu5EpDpSeW09AFgQ,47700
7+
hyperscan/_version.py,sha256=-_OxJPv2D0J4Tap1QJZo4Z4XyBYoG9M_2-0CsJ35W-I,23
8+
hyperscan/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9+
hyperscan/__init__.pyi,sha256=oRU1eShJUV5-mQheZfDCbZYTpVWPyS0dHrhmbT0ewiI,10768
10+
hyperscan/_hs_ext.cpython-311-x86_64-linux-gnu.so,sha256=KIaQV29IP80Ed1uJgU38d8nX4nBhDvzbugfr5fX2XnE,7051104

0 commit comments

Comments
 (0)