Bugfixes #3
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: Lint | |
on: | |
workflow_call: | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
Run: | |
runs-on: ubuntu-latest | |
steps: | |
# Setup | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
# We must fetch at least the immediate parents so that if this is | |
# a pull request then we can checkout the head. | |
fetch-depth: 2 | |
- name: Get Branch Name and remove refs/heads prefix from github.ref (if exists) | |
run: | | |
if [[ ${{ github.ref }} == refs/heads/* ]]; then | |
BRANCH_NAME=$(echo "${{ github.ref }}" | cut -c 12-) | |
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
else | |
echo "BRANCH_NAME=${{ github.ref }}" >> $GITHUB_ENV | |
fi | |
# Configure Git | |
- name: Git configuration | |
run: | | |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "GitHub Actions" | |
# Formatter | |
- name: Setup Biome | |
uses: michijs/.github/.github/workflows/runtime/install.yml@main | |
with: | |
package: -g @biomejs/biome | |
- name: Import Biome config file | |
run: wget -O biome.json https://raw.githubusercontent.com/michijs/.github/main/biome.json | |
- name: Run Biome format | |
run: biome format --write --json . | |
- name: Remove biome file | |
run: rm biome.json | |
- name: Check for changes | |
run: | | |
if git diff-index --quiet HEAD --; then | |
echo "No changes detected. Skipping next format steps." | |
else | |
echo "Changes detected. Proceeding with next steps." | |
echo "FORMAT_CHANGES_DETECTED=true" >> $GITHUB_ENV | |
fi | |
- name: Commit changes | |
if: env.FORMAT_CHANGES_DETECTED == 'true' | |
run: | | |
git add . | |
git commit -m "Format changes" | |
- name: Push changes | |
if: env.FORMAT_CHANGES_DETECTED == 'true' | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ env.BRANCH_NAME }} | |
# Linter | |
- name: Check if branch contains 'dependabot' | |
run: | | |
if [[ "${{ env.BRANCH_NAME }}" == *dependabot* ]]; then | |
echo "Branch contains 'dependabot'. Linter will not run." | |
echo "DEPENDABOT_DETECTED=true" >> $GITHUB_ENV | |
else | |
echo "Branch does not contain 'dependabot'. Linter will run." | |
fi | |
- name: Import Biome config file | |
if: env.DEPENDABOT_DETECTED != 'true' | |
run: wget -O biome.json https://raw.githubusercontent.com/michijs/.github/main/biome.json | |
- name: Run Biome check | |
if: env.DEPENDABOT_DETECTED != 'true' | |
run: biome check --apply . || true | |
- name: Remove biome file | |
if: env.DEPENDABOT_DETECTED != 'true' | |
run: rm biome.json | |
- name: Check for changes | |
if: env.DEPENDABOT_DETECTED != 'true' | |
run: | | |
if git diff-index --quiet HEAD --; then | |
echo "No changes detected. Skipping next steps." | |
else | |
echo "Changes detected. Proceeding with next steps." | |
echo "CHANGES_DETECTED=true" >> $GITHUB_ENV | |
fi | |
- name: Delete existing branch (if exists) | |
if: env.DEPENDABOT_DETECTED != 'true' | |
run: | | |
git push origin --delete ${{ env.BRANCH_NAME }}_lint || true | |
- name: Create new branch | |
if: env.CHANGES_DETECTED == 'true' | |
run: git checkout -b ${{ env.BRANCH_NAME }}_lint | |
- name: Commit changes | |
if: env.CHANGES_DETECTED == 'true' | |
run: | | |
git add . | |
git commit -m "Linting changes" | |
- name: Push changes | |
if: env.CHANGES_DETECTED == 'true' | |
uses: ad-m/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ env.BRANCH_NAME }}_lint | |
- name: Create pull request | |
if: env.CHANGES_DETECTED == 'true' | |
continue-on-error: true | |
run: | | |
SUGGESTIONS=$(biome check --json . 2>&1 || true) | |
gh pr create -B ${{ env.BRANCH_NAME }} -H ${{ env.BRANCH_NAME }}_lint --title 'Linting changes' --body "This pull request includes linting changes based on the target branch. | |
Please review and merge if everything looks good. | |
<details> | |
<summary>Additional suggestions:</summary> | |
${SUGGESTIONS} | |
</details> | |
" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |