Skip to content

Test Rules (staging + prod) #1954

Test Rules (staging + prod)

Test Rules (staging + prod) #1954

Workflow file for this run

name: Test Rules (staging + prod)
on:
push:
branches:
- "**"
pull_request:
schedule:
# run every day at 9am UTC
- cron: '0 9 * * *'
workflow_call:
jobs:
extract-languages:
runs-on: ubuntu-latest
outputs:
languages: ${{ steps.extract.outputs.languages }}
steps:
- uses: actions/checkout@v4
- id: extract
name: Extract languages from file
run: |
relative_path="crates/cli/src/datadog_utils.rs"
if [ ! -f "$relative_path" ]; then
echo "::error::Could not find file `$relative_path`"
exit 1
fi
concat_languages=$(
# Find the definition of the slice
grep -Poz 'const DEFAULT_RULESETS_LANGUAGES: &\[&str\] = &\[\s*?(?:.*?\s*)+?\s*?\];' "$relative_path" |
# Strip the null byte added by -z
tr '\0' '\n' |
# Get any strings present
grep -Po '"[^"]*"' |
# Delete quotation marks
tr -d '"' |
# Convert each newline to a space
tr '\n' ' ' |
# Strip a trailing space
sed 's/ $//'
)
if [ -z "$concat_languages" ]; then
echo "::error::Could not parse default ruleset languages from file `$relative_path`"
exit 1
fi
echo "languages=$concat_languages" >> $GITHUB_OUTPUT
production_rules:
needs: extract-languages
runs-on: ubuntu-latest
env:
DD_SITE: datadoghq.com
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/[email protected]
with:
components: clippy
- name: Test all production rules
run: |
cargo build --profile release-dev --bin datadog-static-analyzer && \
cargo build --profile release-dev --bin datadog-static-analyzer-server && \
sudo apt-get install python3-requests && \
for language in ${{ needs.extract-languages.outputs.languages }}; do \
python misc/test-rules.py -c $PWD/target/release-dev/datadog-static-analyzer -s $PWD/target/release-dev/datadog-static-analyzer-server -l $language ; \
done
staging_rules:
needs: extract-languages
runs-on: ubuntu-latest
env:
DD_SITE: datad0g.com
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/[email protected]
with:
components: clippy
- name: Test all staging rules
run: |
cargo build --profile release-dev --bin datadog-static-analyzer && \
cargo build --profile release-dev --bin datadog-static-analyzer-server && \
sudo apt-get install python3-requests && \
for language in ${{ needs.extract-languages.outputs.languages }}; do \
python misc/test-rules.py -c $PWD/target/release-dev/datadog-static-analyzer -s $PWD/target/release-dev/datadog-static-analyzer-server -l $language ; \
done