From 7e3c369e8768627e0a651eee96eda1be1a5f92be Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 1 Nov 2024 05:58:48 -0500 Subject: [PATCH] Trunk fmt on comment --- .github/workflows/trunk_format_pr.yml | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/trunk_format_pr.yml diff --git a/.github/workflows/trunk_format_pr.yml b/.github/workflows/trunk_format_pr.yml new file mode 100644 index 000000000..d9b584a12 --- /dev/null +++ b/.github/workflows/trunk_format_pr.yml @@ -0,0 +1,45 @@ +name: Run Trunk Fmt on PR Comment + +on: + issue_comment: + types: [created] + +jobs: + trunk-fmt: + if: github.event.issue.pull_request != null && contains(github.event.comment.body, 'trunk fmt') + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + token: ${{ secrets.ARTIFACTS_TOKEN }} + + - name: Set up Trunk + run: | + curl -fsSL https://get.trunk.io -o get-trunk.sh + sh get-trunk.sh -y + + - name: Run Trunk Fmt + run: trunk fmt + + - name: Commit and push changes + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add . + git commit -m "Add firmware version ${{ steps.version.outputs.version }}" + git push + + - name: Comment on PR + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: '`trunk fmt` has been run on this PR.' + })