From d86a5cf3e32caefed89d2ab464ecf697f821a527 Mon Sep 17 00:00:00 2001 From: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com> Date: Thu, 16 May 2024 17:19:37 +0000 Subject: [PATCH] feat: /build slash command added --- .github/workflows/slash-build-command.yml | 35 +++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/slash-build-command.yml diff --git a/.github/workflows/slash-build-command.yml b/.github/workflows/slash-build-command.yml new file mode 100644 index 0000000..06cdb6f --- /dev/null +++ b/.github/workflows/slash-build-command.yml @@ -0,0 +1,35 @@ +name: Slash Build Command +on: + issue_comment: + types: [created] +jobs: + comment_created_by_maintainer: + if: ${{ contains(github.event.comment.body, '/build') && github.actor == "tanmoysrt" }} + runs-on: ubuntu-latest + steps: + - name: Check args + run: | + IFS=' ' read -r -a args <<< ${{ github.event.comment.body }} + if [ ${#args[@]} -ne 3 ]; then + print_error "Invalid number of arguments. Usage: $0 \"/build \"" + fi + app_name="${args[1]}" + version="${args[2]}" + if [ -z "$app_name" ] || [ -z "$version" ]; then + print_error "App name or version is blank." + fi + echo "APP_NAME=$app_name" >> $GITHUB_ENV + echo "VERSION=$version" >> $GITHUB_ENV + echo "Parsed arguments: App Name: $app_name, Version: $version" + + - name: Add reaction + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ github.event.comment.id }} + reactions: +1 + - name: Trigger build + run: | + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/actions/workflows/build-image.yml/dispatches \ + -d '{"ref":"main", "inputs":{"app_name":"${{ env.APP_NAME }}", "version": "${{ env.VERSION }}"}}' \ No newline at end of file