Skip to content

Commit

Permalink
Merge pull request #734 from straight-shoota/infra/script-validate-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored Feb 8, 2024
2 parents c27aa54 + 2a26e0a commit 79d5443
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/validate-content.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Validate content
on:
push:
pull_request:
branches: [master, release/*]
schedule:
- cron: '0 5 * * 1' # Every Monday 5 AM UTC

jobs:
validate-flags:
name: Validate flags
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: macos-latest
- os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Download source
uses: actions/checkout@v4
- name: Install Crystal
uses: crystal-lang/install-crystal@v1
with:
crystal: nightly
- name: Run test script
run: scripts/validate-flags.sh
32 changes: 32 additions & 0 deletions scripts/validate-flags.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#! /bin/sh

set -eu

CRYSTAL=${CRYSTAL:-crystal}
CRYSTAL_PATH="$($CRYSTAL env CRYSTAL_PATH)"
STDLIB_SRC="${CRYSTAL_PATH#*:}" # stdlib source directory is the last entry in CRYSTAL_PATH

filter_missing() {
missing=0

while read -r word; do
grep -q "\`$word\`" docs/syntax_and_semantics/compile_time_flags.md || {
[ ${missing} -eq 0 ] && echo "# Missing ${1} flags:"
echo "$word"
missing=1
}
done
return ${missing}
}

status=0
find "${STDLIB_SRC}" -name '*.cr' -type f -not -path "${STDLIB_SRC}/compiler/**" -print0 \
| xargs -0 "${CRYSTAL}" tool flags \
| filter_missing "stdlib" || status=1

{
${CRYSTAL} tool flags "${STDLIB_SRC}/compiler"
grep --no-file -o -R -P '(?<=has_flag\?[( ]")[^"]+' "${STDLIB_SRC}/compiler"
} | sort -u | filter_missing "compiler" || status=1

exit ${status}

0 comments on commit 79d5443

Please sign in to comment.