From 5883e6d0d5de32e59347e91281f43325442850a9 Mon Sep 17 00:00:00 2001 From: GoldenAnpu Date: Thu, 22 Feb 2024 13:15:16 +0100 Subject: [PATCH] - add pylint check on PR updates - remove pylint check on release --- .github/workflows/build-push-release.yml | 194 +----------------- .../workflows/manual-check-with-pylint.yml | 172 ---------------- .github/workflows/pr-check-with-pylint.yml | 176 ++++++++++++++++ 3 files changed, 182 insertions(+), 360 deletions(-) delete mode 100644 .github/workflows/manual-check-with-pylint.yml create mode 100644 .github/workflows/pr-check-with-pylint.yml diff --git a/.github/workflows/build-push-release.yml b/.github/workflows/build-push-release.yml index 7ddefe5..c0ad4a7 100644 --- a/.github/workflows/build-push-release.yml +++ b/.github/workflows/build-push-release.yml @@ -1,183 +1,13 @@ name: build-push-release on: - workflow_dispatch: release: types: [published] jobs: - pylint: - runs-on: ubuntu-latest - env: - ISSUES_URL: "https://api.github.com/repos/supervisely/issues/issues" - PROJECT_NUMBER: "2" - TODO_NAME: "🚀 Todo (now!)" - STATUS_FIELD_ID: "" - STATUS_ID: "" - ISSUE_NODE_ID: "" - ITEM_TO_MOVE: "" - ORG_PROJECT_ID: "" - ORG_LOGIN: "supervisely" - ERRORS_DETECTED: false - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: ${{ github.repository }} - token: ${{ secrets.PYLINT_TOKEN }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install python-all-dev libboost-python-dev libexiv2-dev - sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python310.so /usr/lib/x86_64-linux-gnu/libboost_python38.so - pip install --upgrade pip - pip install pylint - pip install -r requirements.txt - - - name: Run check with pylint - run: | - export PYTHONPATH=$PYTHONPATH:$PWD/agent/ - pylint_output=$(pylint --ignore-patterns=".*\.json$|.*\.gitignore$" "agent") || true - if [[ $pylint_output == *"E"* ]] || [[ $pylint_output == *"F"* ]]; then - # Save pylint output to a file - echo "$pylint_output" > pylint_errors.txt - echo "ERRORS_DETECTED=true" >> $GITHUB_ENV - else - echo "ERRORS_DETECTED=false" >> $GITHUB_ENV - fi - id: pylint - - - name: Create GitHub issue - run: | - if [[ "${{ env.ERRORS_DETECTED }}" == "true" ]]; then - issue_body=$(cat pylint_errors.txt) - echo "Issue body: $issue_body" - - json=$(jq -n \ - --arg title "Pylint Errors for ${{ github.event_name }} #${{ github.event.release.tag_name }} at $(date -u +'%Y-%m-%d %H:%M') UTC+0" \ - --arg body "$issue_body" \ - --argjson assignees '["${{ github.actor }}"]' \ - --argjson labels '["bug", "pylint", "agent"]' \ - '{title: $title, body: $body, assignees: $assignees, labels: $labels}') - - issue_response=$(curl -X POST -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - ${{ env.ISSUES_URL }} \ - -d "$json" - ) - - echo "GitHub response: $issue_response" - issue_url=$(echo "$issue_response" | jq -r '.html_url') - echo "issue_url=$issue_url" >> $GITHUB_ENV - issue_node_id=$(echo "$issue_response" | jq -r '.node_id') - echo "ISSUE_NODE_ID=$issue_node_id" >> $GITHUB_ENV - - else - echo "No pylint errors detected." - fi - - - - name: Get Project ID - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - org_login=${{ env.ORG_LOGIN }} - project_number=${{ env.PROJECT_NUMBER }} - - response=$(curl -X POST \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d '{ - "query": "query getProjectID($org_login: String!, $project_number: Int!) { organization(login: $org_login) { projectV2(number: $project_number) { id } } }", - "variables": { - "org_login": "${{ env.ORG_LOGIN }}", - "project_number": ${{ env.PROJECT_NUMBER }} - } - }' \ - https://api.github.com/graphql) - echo "Response from GitHub API: $response" - project_id=$(echo "$response" | jq -r '.data.organization.projectV2.id') - - echo "Organization Project ID: $project_id" - echo "ORG_PROJECT_ID=$project_id" >> $GITHUB_ENV - - - name: Get Status Field ID and Status ID - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - response=$(curl -X POST \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Content-Type: application/json" \ - --data-raw '{ - "query": "query getProjectFields($projectId: ID!) { node(id: $projectId) { ... on ProjectV2 { fields(first: 100) { nodes { ... on ProjectV2Field { id dataType name } ... on ProjectV2IterationField { id name dataType configuration { iterations { startDate id } } } ... on ProjectV2SingleSelectField { id name dataType options { id name } } } } } } }", - "variables": { - "projectId": "${{ env.ORG_PROJECT_ID}}" - } - }' \ - https://api.github.com/graphql) - echo "Response from GitHub API: $response" - status_field_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .id') - status_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .options[] | select(.name == "${{ env.TODO_NAME }}") | .id') - echo "STATUS_FIELD_ID=$status_field_id" >> $GITHUB_ENV - echo "STATUS_ID=$status_id" >> $GITHUB_ENV - echo "Status Field ID: $status_id" - echo "Todo ID: $todo_id" - - - name: Add Issue to project - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - issue_id=${{ env.ISSUE_NODE_ID }} - project_id=${{ env.ORG_PROJECT_ID }} - - item_id=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/graphql \ - -d @- <> $GITHUB_ENV - - - name: Move issue to Todo column - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" -H "Content-Type: application/json" -d '{ - "query": "mutation { set_status: updateProjectV2ItemFieldValue(input: { projectId: \"${{ env.ORG_PROJECT_ID }}\", itemId: \"${{env.ITEM_TO_MOVE}}\", fieldId: \"${{ env.STATUS_FIELD_ID}}\", value: { singleSelectOptionId: \"${{ env.STATUS_ID }}\" } }) { projectV2Item { id } } }" - }' https://api.github.com/graphql - - - name: Complete with exit code 1 - if: ${{ env.ERRORS_DETECTED == 'true' }} - id: set_status - run: | - echo "RESULT=failure" >> $GITHUB_ENV - exit 1 - - build: runs-on: ubuntu-latest - needs: pylint - if: ${{ needs.pylint.result == 'success' }} + steps: - name: Free Disk Space (Ubuntu) uses: jlumbroso/free-disk-space@main @@ -192,24 +22,12 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - - name: Write Tag to ENV variable - run: | - if [[ "${{ github.event_name }}" == "release" ]]; then - echo "LABEL_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV - else - response=$(curl \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "https://api.github.com/repos/${{ github.repository }}/releases/latest") - echo "Response: $response" - LATEST_RELEASE_TAG=$(echo "$response" | jq -r .tag_name) - echo "LABEL_VERSION=$LATEST_RELEASE_TAG" >> $GITHUB_ENV - fi - - name: Echo ${{ env.LABEL_VERSION }} - run: echo ${{ env.LABEL_VERSION }} + - name: Echo ${{ github.event.release.tag_name }} + run: echo ${{ github.event.release.tag_name }} + + - name: Write Tag to ENV variable + run: echo "LABEL_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV - name: Login to DockerHub uses: docker/login-action@v1 diff --git a/.github/workflows/manual-check-with-pylint.yml b/.github/workflows/manual-check-with-pylint.yml deleted file mode 100644 index c11782f..0000000 --- a/.github/workflows/manual-check-with-pylint.yml +++ /dev/null @@ -1,172 +0,0 @@ -name: Checking agent files with pylint - -on: - workflow_dispatch: - -jobs: - pylint: - runs-on: ubuntu-latest - env: - ISSUES_URL: "https://api.github.com/repos/supervisely/issues/issues" - PROJECT_NUMBER: "2" - TODO_NAME: "🚀 Todo (now!)" - STATUS_FIELD_ID: "" - STATUS_ID: "" - ISSUE_NODE_ID: "" - ITEM_TO_MOVE: "" - ORG_PROJECT_ID: "" - ORG_LOGIN: "supervisely" - ERRORS_DETECTED: false - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: ${{ github.repository }} - token: ${{ secrets.PYLINT_TOKEN }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - sudo apt-get update - sudo apt-get install python-all-dev libboost-python-dev libexiv2-dev - sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python310.so /usr/lib/x86_64-linux-gnu/libboost_python38.so - pip install --upgrade pip - pip install pylint - pip install -r requirements.txt - - - name: Run check with pylint - run: | - export PYTHONPATH=$PYTHONPATH:$PWD/agent/ - pylint_output=$(pylint --ignore-patterns=".*\.json$|.*\.gitignore$" "agent") || true - if [[ $pylint_output == *"E"* ]] || [[ $pylint_output == *"F"* ]]; then - # Save pylint output to a file - echo "$pylint_output" > pylint_errors.txt - echo "ERRORS_DETECTED=true" >> $GITHUB_ENV - else - echo "ERRORS_DETECTED=false" >> $GITHUB_ENV - fi - id: pylint - - - name: Create GitHub issue - run: | - if [[ "${{ env.ERRORS_DETECTED }}" == "true" ]]; then - issue_body=$(cat pylint_errors.txt) - echo "Issue body: $issue_body" - - json=$(jq -n \ - --arg title "[Manual Run] Pylint Errors for #${{ github.ref_name }} at $(date -u +'%Y-%m-%d %H:%M') UTC+0" \ - --arg body "$issue_body" \ - --argjson assignees '["${{ github.actor }}"]' \ - --argjson labels '["bug", "pylint", "agent"]' \ - '{title: $title, body: $body, assignees: $assignees, labels: $labels}') - - issue_response=$(curl -X POST -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - ${{ env.ISSUES_URL }} \ - -d "$json" - ) - - echo "GitHub response: $issue_response" - issue_url=$(echo "$issue_response" | jq -r '.html_url') - echo "issue_url=$issue_url" >> $GITHUB_ENV - issue_node_id=$(echo "$issue_response" | jq -r '.node_id') - echo "ISSUE_NODE_ID=$issue_node_id" >> $GITHUB_ENV - - else - echo "No pylint errors detected." - fi - - - - name: Get Project ID - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - org_login=${{ env.ORG_LOGIN }} - project_number=${{ env.PROJECT_NUMBER }} - - response=$(curl -X POST \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Content-Type: application/json" \ - -d '{ - "query": "query getProjectID($org_login: String!, $project_number: Int!) { organization(login: $org_login) { projectV2(number: $project_number) { id } } }", - "variables": { - "org_login": "${{ env.ORG_LOGIN }}", - "project_number": ${{ env.PROJECT_NUMBER }} - } - }' \ - https://api.github.com/graphql) - echo "Response from GitHub API: $response" - project_id=$(echo "$response" | jq -r '.data.organization.projectV2.id') - - echo "Organization Project ID: $project_id" - echo "ORG_PROJECT_ID=$project_id" >> $GITHUB_ENV - - - name: Get Status Field ID and Status ID - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - response=$(curl -X POST \ - -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Content-Type: application/json" \ - --data-raw '{ - "query": "query getProjectFields($projectId: ID!) { node(id: $projectId) { ... on ProjectV2 { fields(first: 100) { nodes { ... on ProjectV2Field { id dataType name } ... on ProjectV2IterationField { id name dataType configuration { iterations { startDate id } } } ... on ProjectV2SingleSelectField { id name dataType options { id name } } } } } } }", - "variables": { - "projectId": "${{ env.ORG_PROJECT_ID}}" - } - }' \ - https://api.github.com/graphql) - echo "Response from GitHub API: $response" - status_field_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .id') - status_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .options[] | select(.name == "${{ env.TODO_NAME }}") | .id') - echo "STATUS_FIELD_ID=$status_field_id" >> $GITHUB_ENV - echo "STATUS_ID=$status_id" >> $GITHUB_ENV - echo "Status Field ID: $status_id" - echo "Todo ID: $todo_id" - - - name: Add Issue to project - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - issue_id=${{ env.ISSUE_NODE_ID }} - project_id=${{ env.ORG_PROJECT_ID }} - - item_id=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/graphql \ - -d @- <> $GITHUB_ENV - - - name: Move issue to Todo column - if: ${{ env.ERRORS_DETECTED == 'true' }} - run: | - curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" -H "Content-Type: application/json" -d '{ - "query": "mutation { set_status: updateProjectV2ItemFieldValue(input: { projectId: \"${{ env.ORG_PROJECT_ID }}\", itemId: \"${{env.ITEM_TO_MOVE}}\", fieldId: \"${{ env.STATUS_FIELD_ID}}\", value: { singleSelectOptionId: \"${{ env.STATUS_ID }}\" } }) { projectV2Item { id } } }" - }' https://api.github.com/graphql - - - name: Complete with exit code 1 - if: ${{ env.ERRORS_DETECTED == 'true' }} - id: set_status - run: | - echo "RESULT=failure" >> $GITHUB_ENV - exit 1 \ No newline at end of file diff --git a/.github/workflows/pr-check-with-pylint.yml b/.github/workflows/pr-check-with-pylint.yml new file mode 100644 index 0000000..d62d1c9 --- /dev/null +++ b/.github/workflows/pr-check-with-pylint.yml @@ -0,0 +1,176 @@ +name: pr-check-with-pylint + +on: + pull_request: + types: [opened, synchronize, reopened] + workflow_dispatch: + +jobs: + pylint: + runs-on: ubuntu-latest + env: + ISSUES_URL: "https://api.github.com/repos/supervisely/issues/issues" + PROJECT_NUMBER: "2" + TODO_NAME: "🚀 Todo (now!)" + STATUS_FIELD_ID: "" + STATUS_ID: "" + ISSUE_NODE_ID: "" + ITEM_TO_MOVE: "" + ORG_PROJECT_ID: "" + ORG_LOGIN: "supervisely" + ERRORS_DETECTED: false + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }} + token: ${{ secrets.PYLINT_TOKEN }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.8 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install python-all-dev libboost-python-dev libexiv2-dev + sudo ln -s /usr/lib/x86_64-linux-gnu/libboost_python310.so /usr/lib/x86_64-linux-gnu/libboost_python38.so + pip install --upgrade pip + pip install pylint + pip install -r requirements.txt + + + - name: Run check with pylint + run: | + export PYTHONPATH=$PYTHONPATH:$PWD/agent/ + pylint_output=$(pylint --ignore-patterns=".*\.json$|.*\.gitignore$" "agent") || true + if [[ $pylint_output == *"E"* ]] || [[ $pylint_output == *"F"* ]]; then + # Save pylint output to a file + echo "$pylint_output" > pylint_errors.txt + echo "ERRORS_DETECTED=true" >> $GITHUB_ENV + else + echo "ERRORS_DETECTED=false" >> $GITHUB_ENV + fi + id: pylint + + - name: Fail if pylint errors detected + if: ${{ env.ERRORS_DETECTED == 'true' }} + run: | + issue_body=$(cat pylint_errors.txt) + echo "Pylint Errors: $issue_body" + echo "RESULT=failure" >> $GITHUB_ENV + exit 1 + + # - name: Create GitHub issue + # run: | + # if [[ "${{ env.ERRORS_DETECTED }}" == "true" ]]; then + # issue_body=$(cat pylint_errors.txt) + # echo "Issue body: $issue_body" + + # json=$(jq -n \ + # --arg title "Pylint Errors for ${{ github.event_name }} #${{ github.event.release.tag_name }} at $(date -u +'%Y-%m-%d %H:%M') UTC+0" \ + # --arg body "$issue_body" \ + # --argjson assignees '["${{ github.actor }}"]' \ + # --argjson labels '["bug", "pylint", "agent"]' \ + # '{title: $title, body: $body, assignees: $assignees, labels: $labels}') + + # issue_response=$(curl -X POST -H "Accept: application/vnd.github+json" \ + # -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ + # -H "X-GitHub-Api-Version: 2022-11-28" \ + # ${{ env.ISSUES_URL }} \ + # -d "$json" + # ) + + # echo "GitHub response: $issue_response" + # issue_url=$(echo "$issue_response" | jq -r '.html_url') + # echo "issue_url=$issue_url" >> $GITHUB_ENV + # issue_node_id=$(echo "$issue_response" | jq -r '.node_id') + # echo "ISSUE_NODE_ID=$issue_node_id" >> $GITHUB_ENV + + # else + # echo "No pylint errors detected." + # fi + + + # - name: Get Project ID + # if: ${{ env.ERRORS_DETECTED == 'true' }} + # run: | + # org_login=${{ env.ORG_LOGIN }} + # project_number=${{ env.PROJECT_NUMBER }} + + # response=$(curl -X POST \ + # -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ + # -H "Content-Type: application/json" \ + # -d '{ + # "query": "query getProjectID($org_login: String!, $project_number: Int!) { organization(login: $org_login) { projectV2(number: $project_number) { id } } }", + # "variables": { + # "org_login": "${{ env.ORG_LOGIN }}", + # "project_number": ${{ env.PROJECT_NUMBER }} + # } + # }' \ + # https://api.github.com/graphql) + # echo "Response from GitHub API: $response" + # project_id=$(echo "$response" | jq -r '.data.organization.projectV2.id') + + # echo "Organization Project ID: $project_id" + # echo "ORG_PROJECT_ID=$project_id" >> $GITHUB_ENV + + # - name: Get Status Field ID and Status ID + # if: ${{ env.ERRORS_DETECTED == 'true' }} + # run: | + # response=$(curl -X POST \ + # -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ + # -H "Content-Type: application/json" \ + # --data-raw '{ + # "query": "query getProjectFields($projectId: ID!) { node(id: $projectId) { ... on ProjectV2 { fields(first: 100) { nodes { ... on ProjectV2Field { id dataType name } ... on ProjectV2IterationField { id name dataType configuration { iterations { startDate id } } } ... on ProjectV2SingleSelectField { id name dataType options { id name } } } } } } }", + # "variables": { + # "projectId": "${{ env.ORG_PROJECT_ID}}" + # } + # }' \ + # https://api.github.com/graphql) + # echo "Response from GitHub API: $response" + # status_field_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .id') + # status_id=$(echo "$response" | jq -r '.data.node.fields.nodes[] | select(.name == "Status") | .options[] | select(.name == "${{ env.TODO_NAME }}") | .id') + # echo "STATUS_FIELD_ID=$status_field_id" >> $GITHUB_ENV + # echo "STATUS_ID=$status_id" >> $GITHUB_ENV + # echo "Status Field ID: $status_id" + # echo "Todo ID: $todo_id" + + # - name: Add Issue to project + # if: ${{ env.ERRORS_DETECTED == 'true' }} + # run: | + # issue_id=${{ env.ISSUE_NODE_ID }} + # project_id=${{ env.ORG_PROJECT_ID }} + + # item_id=$(curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" \ + # -H "Accept: application/vnd.github.v3+json" \ + # https://api.github.com/graphql \ + # -d @- <> $GITHUB_ENV + + # - name: Move issue to Todo column + # if: ${{ env.ERRORS_DETECTED == 'true' }} + # run: | + # curl -X POST -H "Authorization: Bearer ${{ secrets.PYLINT_TOKEN }}" -H "Content-Type: application/json" -d '{ + # "query": "mutation { set_status: updateProjectV2ItemFieldValue(input: { projectId: \"${{ env.ORG_PROJECT_ID }}\", itemId: \"${{env.ITEM_TO_MOVE}}\", fieldId: \"${{ env.STATUS_FIELD_ID}}\", value: { singleSelectOptionId: \"${{ env.STATUS_ID }}\" } }) { projectV2Item { id } } }" + # }' https://api.github.com/graphql \ No newline at end of file