From f3d1c98d6d14384e91eb4d46ad9ed2ff734981d4 Mon Sep 17 00:00:00 2001 From: Michael Chris Lopez Date: Fri, 29 Oct 2021 17:11:23 +0800 Subject: [PATCH] add format workflow --- .github/workflows/format.yml | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..e2d0f41 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,46 @@ +name: Format +on: + push: + paths: + - 'lua/**.lua' + - '**.md' + - '.github/**.yml' + branches: [main, dev] + +jobs: + format: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + STYLUA_VERSION: 0.11.0 + steps: + - uses: actions/checkout@v2 + + - name: Setup git + run: | + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + printf 'STYLE_BRANCH=bot/style/%s\n' ${GITHUB_REF#refs/heads/} >> $GITHUB_ENV + + - name: Apply stylua + run: | + git checkout -b ${STYLE_BRANCH} + curl -Lo /tmp/stylua.zip https://github.com/JohnnyMorganz/StyLua/releases/download/v${STYLUA_VERSION}/stylua-${STYLUA_VERSION}-linux.zip + unzip -d /tmp/ /tmp/stylua.zip + chmod +x /tmp/stylua + /tmp/stylua --config-path=.stylua.toml lua/ + + - name: Apply prettier + uses: creyD/prettier_action@v4.0 + + - name: Create PR + run: | + if ! [[ -z $(git status -s) ]]; then + git add -u + git commit -m "chore: format" + git push --force https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY} ${STYLE_BRANCH} + gh pr create --fill --base ${GITHUB_REF#refs/heads/} --head ${STYLE_BRANCH} || true + fi