From 6ae7893602624b9437f88b60eec0c00bbf23134d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20M=C3=BCller?= Date: Fri, 8 Nov 2024 12:40:11 +0100 Subject: [PATCH] [CI] Refactor `Validate Flags` workflow (#793) * Check out the Crystal repo associated with the target branch (`release/1.14` for `release/1.14`). * Run workflow only on `ubuntu-latest`. There's no reason to run this on different platforms. `crystal tool flags` operates on the raw source code and does not take platform differences into account. * Run workflow only when `docs/syntax_and_semantics/compile_time_flags.md` is changed to avoid noise in unrelated PRs --- .github/workflows/validate-content.yml | 25 +++++++++++++++++-------- scripts/validate-flags.sh | 12 ++++++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/validate-content.yml b/.github/workflows/validate-content.yml index 0a50cbd98..e7388613a 100644 --- a/.github/workflows/validate-content.yml +++ b/.github/workflows/validate-content.yml @@ -1,22 +1,21 @@ name: Validate content on: push: + paths: + - docs/syntax_and_semantics/compile_time_flags.md + - .github/workflows/validate-content.yml pull_request: branches: [master, release/*] + paths: + - docs/syntax_and_semantics/compile_time_flags.md + - .github/workflows/validate-content.yml 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 }} + runs-on: ubuntu-latest steps: - name: Download source uses: actions/checkout@v4 @@ -24,5 +23,15 @@ jobs: uses: crystal-lang/install-crystal@v1 with: crystal: nightly + - name: Download crystal repo + uses: actions/checkout@v4 + with: + repository: crystal-lang/crystal + path: crystal + # If the PR goes against a release branch, we checkout that same release + # branch in the Crystal repo (names are identical). + ref: ${{ (startsWith(github.base_ref, 'release/') && github.base_ref) || 'master' }} - name: Run test script run: scripts/validate-flags.sh + env: + STDLIB_SRC: ./crystal/src diff --git a/scripts/validate-flags.sh b/scripts/validate-flags.sh index e5aafdfad..3f316abed 100755 --- a/scripts/validate-flags.sh +++ b/scripts/validate-flags.sh @@ -1,10 +1,14 @@ -#! /bin/sh +#! /bin/bash -set -eu +set -eu -o pipefail CRYSTAL=${CRYSTAL:-crystal} -CRYSTAL_PATH="$($CRYSTAL env CRYSTAL_PATH)" -STDLIB_SRC="${CRYSTAL_PATH#*:}" # stdlib source directory is the last entry in CRYSTAL_PATH +if [ -z "${STDLIB_SRC-}" ]; then + CRYSTAL_PATH="$($CRYSTAL env CRYSTAL_PATH)" + STDLIB_SRC="${CRYSTAL_PATH#*:}" # stdlib source directory is the last entry in CRYSTAL_PATH +fi + +echo "Validating flags for stdlib source ${STDLIB_SRC} ($(cat "${STDLIB_SRC}/VERSION"))" filter_missing() { missing=0