From 9ec681df052c5d185c42d139da82b70dec4122c8 Mon Sep 17 00:00:00 2001 From: Tushar Date: Tue, 16 Jun 2020 00:40:41 +0530 Subject: [PATCH] Added support for chatops using prettier and github actions Formatting will happen only when we use /style in conversation of a PR Currently, it formats the files with .js .html and .css extensions --- .github/workflows/prettier.yml | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/prettier.yml diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..c0ba2fe --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,38 @@ +on: + issue_comment: + types: [created] +name: Commands +jobs: + style: + if: startsWith(github.event.comment.body, '/style') + name: style + runs-on: ubuntu-latest + steps: + - name: Install yarn + run: | + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - + echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list + sudo apt update + sudo apt install yarn + + - uses: actions/checkout@v2 + - name: Initialize yarn + run: | + yarn init -y + yarn add -E prettier + - uses: r-lib/actions/pr-fetch@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run yarn + run: yarn run prettier --write '**/*.{css,js,html}' + + - name: commit + run: | + git add \*.css \*.html \*.js + git config --global user.email "bot@example.com" + git config --global user.name "Bot" + if [[ $(git diff --name-only --cached) != "" ]]; then git commit -m 'automated syle update' ; fi + - uses: r-lib/actions/pr-push@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }}