Streamline the autoformat workflow to enable version pinning for all platforms #1344
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Autoformat | |
on: | |
pull_request: | |
paths-ignore: | |
- "README.MD" | |
types: [opened, synchronize, reopened, ready_for_review] | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "README.MD" | |
- '.gitignore' | |
jobs: | |
check-format: | |
name: Enforce consistent formatting | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ ubuntu-latest, macos-latest, windows-latest ] | |
include: | |
- os: ubuntu-latest | |
stylua: stylua-linux.zip | |
shell: bash | |
- os: macos-latest | |
stylua: stylua-macos.zip | |
shell: bash | |
- os: windows-latest | |
stylua: stylua-win64.zip | |
shell: 'msys2 {0}' | |
env: | |
HOMEBREW_LLVM_DIR: "/opt/homebrew/opt/llvm" # Depends on the runner's architecture | |
defaults: | |
run: | |
shell: ${{ matrix.shell }} | |
steps: | |
- name: Set up MSYS2 environment | |
if: runner.os == 'Windows' | |
uses: msys2/setup-msys2@v2 | |
with: | |
install: git mingw-w64-x86_64-clang unzip | |
path-type: inherit # Not ideal, but $GITHUB_PATH doesn't play nice with MSYS otherwise | |
- name: Disable autocrlf # Messes up everything on Windows since the formatter applies \n | |
run: | | |
git config --global core.autocrlf false | |
git config --global core.eol lf | |
- name: Check out Git repository | |
uses: actions/checkout@v4 | |
with: | |
clean: false | |
fetch-depth: 1 | |
submodules: false | |
- name: Source environment variables | |
run: | | |
set -a | |
source .github/autoformat.env | |
cat .github/autoformat.env >> $GITHUB_ENV | |
echo $GITHUB_ENV | |
set -a | |
- name: Install stylua | |
run: | | |
wget https://github.com/JohnnyMorganz/StyLua/releases/download/${{ env.EVO_STYLUA_VERSION }}/${{ matrix.stylua }} | |
unzip ${{ matrix.stylua }} | |
chmod +x stylua | |
ls -l | |
echo $(pwd) >> $GITHUB_PATH | |
./stylua --version | |
# The preinstalled version is positively antique; replace with the pinned version (to match MSYS) | |
- name: Install clang-format (via APT) | |
if: runner.os == 'Linux' | |
run: ./deps/install-clang-format.sh | |
- name: Install clang-format (via Homebrew) | |
if: runner.os == 'macOS' | |
run: | | |
set -eu | |
brew install llvm@${{ env.EVO_CLANGFORMAT_VERSION }} | |
ls -l ${{ env.HOMEBREW_LLVM_DIR }}@${{ env.EVO_CLANGFORMAT_VERSION }}/bin | |
echo "${{ env.HOMEBREW_LLVM_DIR }}@${{ env.EVO_CLANGFORMAT_VERSION }}/bin" >> $GITHUB_PATH | |
- name: Create versioned clang-format alias | |
if: runner.os != 'Linux' | |
run: | | |
set -eu | |
echo $(which clang-format) | |
ls -l "$(dirname "$(which clang-format)")" | |
ln -s "$(which clang-format)" "$(which clang-format)"-${{ env.EVO_CLANGFORMAT_VERSION }} | |
- name: Verify clang-format version | |
run: clang-format --version && clang-format-${{ env.EVO_CLANGFORMAT_VERSION }} --version | |
- name: Run autoformat | |
run: ./autoformat.sh | |
- name: Check for inconsistent formatting | |
run: git --no-pager diff --exit-code -b . |