From 5d0f1789dfc9c4db513b1a8eca4fb0dd01e83336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michalina=20Ciencia=C5=82a?= Date: Wed, 26 Apr 2023 14:12:48 +0200 Subject: [PATCH] Test workflow creating a PR --- .github/workflows/createPR.yml | 39 ++++++++++++++++++++++++++++------ script.sh | 14 ++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100755 script.sh diff --git a/.github/workflows/createPR.yml b/.github/workflows/createPR.yml index ce101cc..575a006 100644 --- a/.github/workflows/createPR.yml +++ b/.github/workflows/createPR.yml @@ -8,18 +8,22 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Create a pull request + shell: bash {0} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SUCC_COMMAND: "1" run: | echo "Configure" git config --global user.email "michalina.cienciala@akena.co" git config --global user.name "Michalina Cienciala" echo "Checkout" - git checkout auto-update-api-docs || git checkout -b auto-update-api-docs - echo "Pull" - git pull + git checkout auto-update-api-docs-3 || git checkout -b auto-update-api-docs-3 + # echo "Pull" + # git pull echo "Edit" date > newfile.txt echo "Add" @@ -27,6 +31,29 @@ jobs: echo "Commit" git commit -m "Update docs" echo "Push" - git push --set-upstream origin HEAD:auto-update-api-docs - echo "PR" - hub pull-request -m "Update Solidity API docs" # --reviewer [...] --labels [...] + git push --set-upstream origin HEAD:auto-update-api-docs-3 + echo "PR 1" + # set -x + # pr_command=$(hub pull-request --base main --message "Update Solidity API docs" --message "Docs updated by workflow:" 2>&1) + # echo "PR 2" + # if [ $? -eq 0 ] || [[ "$pr_command" == *"A pull request already exists"* ]]; + # then + # echo "PR created (or it already existed)" + # else + # echo "PR creation command failed" + # exit 1 + # fi + + # if hub pull-request --base main --message "Update Solidity API docs" --message "Docs updated by workflow:" | grep -q "A pull request already exists" + # then + # echo "A pull request already exists" + # else + # echo "Pull request created" + # fi + + if ./script.sh | grep -q "A pull request already exists" + then + echo "A pull request already exists" + else + echo "Pull request created" + fi \ No newline at end of file diff --git a/script.sh b/script.sh new file mode 100755 index 0000000..0303d21 --- /dev/null +++ b/script.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +if [[ $SUCC_COMMAND == "0" ]]; +then + echo "Success" + exit 0 +elif [[ $SUCC_COMMAND == "1" ]]; +then + echo "Error creating pull request: Unprocessable Entity (HTTP 422)" + echo "A pull request already exists for michalinacienciala:auto-update-api-docs-3." + exit 1 +else + exit 2 +fi \ No newline at end of file