Repository navigation
95 lines (90 loc) · 3.5 KB
/
Copy pathfunction-comparison.yml
File metadata and controls
95 lines (90 loc) · 3.5 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
# Copyright 2023 Greptime Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Function Comparison
on:
pull_request:
push:
branches:
- main
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
permissions:
contents: read
issues: write
jobs:
compare:
name: Compare Functions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Run function comparison
id: compare
# explicit shell: 'bash' in GitHub Actions means
# `bash --noprofile --norc -eo pipefail`. `set +e` disables errexit
# so the script's exit code can be captured from PIPESTATUS (pipefail
# + `tee` would otherwise mask it) and exposed as a step output.
# Exit codes: 0 = in sync, 1 = mismatch, 2 = operational error.
shell: bash
run: |
set +e
python scripts/compare_functions.py | tee comparison.log
code=${PIPESTATUS[0]}
echo "exit_code=$code" >> "$GITHUB_OUTPUT"
exit "$code"
- name: Create issue on scheduled mismatch
# Only a confirmed mismatch (exit code 1) files an issue. Operational
# failures (exit code 2, e.g. unable to fetch Prometheus functions.go)
# still fail the job but must not create an "out of sync" issue that
# would then suppress a later genuine mismatch report via dedup.
# failure() overrides the implicit success() check after a mismatch.
if: failure() && github.event_name == 'schedule' && steps.compare.outputs.exit_code == '1'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_TITLE="Function comparison failed: Rust functions out of sync with Prometheus"
EXISTING=$(gh issue list \
--repo "${{ github.repository }}" \
--state open \
--search "in:title \"${ISSUE_TITLE}\"" \
--json number \
--jq 'length')
if [ "$EXISTING" -gt 0 ]; then
echo "An open issue already exists, skipping creation."
exit 0
fi
{
echo "The scheduled function comparison detected mismatches."
echo ""
echo "Rust functions in \`src/parser/function.rs\` are out of sync with"
echo "[Prometheus functions.go](https://github.com/prometheus/prometheus/blob/main/promql/parser/functions.go)."
echo ""
echo "See the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details."
echo ""
echo "<details><summary>Comparison output</summary>"
echo ""
echo '```'
cat comparison.log
echo '```'
echo ""
echo "</details>"
} > issue_body.md
gh issue create \
--repo "${{ github.repository }}" \
--title "$ISSUE_TITLE" \
--body-file issue_body.md