From 146a702e2753b1582eeb734d3ce0ea3f50c4a817 Mon Sep 17 00:00:00 2001 From: andrewsy-opal Date: Tue, 26 Nov 2024 13:06:44 -0500 Subject: [PATCH 1/3] add github action to autogen --- .github/workflows/autogen-remote-changes.yml | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/autogen-remote-changes.yml diff --git a/.github/workflows/autogen-remote-changes.yml b/.github/workflows/autogen-remote-changes.yml new file mode 100644 index 0000000..0b7fee7 --- /dev/null +++ b/.github/workflows/autogen-remote-changes.yml @@ -0,0 +1,62 @@ +name: Auto-Update SDK + +on: + schedule: + - cron: "0 0 * * 1" # Runs every Monday at midnight + workflow_dispatch: # Allows manual triggering of the workflow + +jobs: + update-sdk: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + run: | + git clone https://github.com/${{ github.repository }} repo + cd repo + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + - name: Pull and generate SDK + run: | + cd repo + make gen-openapi-remote + - name: Check for changes + run: | + cd repo + if git diff --quiet; then + echo "changes=false" >> $GITHUB_ENV + else + echo "changes=true" >> $GITHUB_ENV + fi + - name: Commit changes + if: env.changes == 'true' + run: | + cd repo + git checkout -b auto-update-sdk || git checkout auto-update-sdk + git add . + git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')" + - name: Push changes + if: env.changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cd repo + git push --force --set-upstream origin auto-update-sdk + - name: Create a pull request + if: env.changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')" + PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK." + curl -H "Authorization: token $GITHUB_TOKEN" \ + -X POST \ + -H "Content-Type: application/json" \ + -d @- \ + https://api.github.com/repos/${{ github.repository }}/pulls < Date: Tue, 26 Nov 2024 13:12:30 -0500 Subject: [PATCH 2/3] test trigger autogen --- .github/workflows/autogen-remote-changes.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/autogen-remote-changes.yml b/.github/workflows/autogen-remote-changes.yml index 0b7fee7..04dc307 100644 --- a/.github/workflows/autogen-remote-changes.yml +++ b/.github/workflows/autogen-remote-changes.yml @@ -1,9 +1,11 @@ name: Auto-Update SDK -on: - schedule: - - cron: "0 0 * * 1" # Runs every Monday at midnight - workflow_dispatch: # Allows manual triggering of the workflow +# on: +# schedule: +# - cron: "0 0 * * 1" # Runs every Monday at midnight +# workflow_dispatch: # Allows manual triggering of the workflow + +on: [push, pull_request] jobs: update-sdk: From 89a7acae7a6072aaefe427d03dc5a0d109dd6ea3 Mon Sep 17 00:00:00 2001 From: andrewsy-opal Date: Tue, 26 Nov 2024 13:16:24 -0500 Subject: [PATCH 3/3] add python --- .github/workflows/autogen-remote-changes.yml | 94 ++++++++++++------- .github/workflows/python.yml | 2 +- .gitlab-ci.yml | 3 - .../templates/github-workflow.mustache | 2 +- .travis.yml | 1 - Makefile | 9 +- config.json | 9 +- requirements.txt | 5 +- test-requirements.txt | 11 ++- 9 files changed, 86 insertions(+), 50 deletions(-) diff --git a/.github/workflows/autogen-remote-changes.yml b/.github/workflows/autogen-remote-changes.yml index 04dc307..13bc201 100644 --- a/.github/workflows/autogen-remote-changes.yml +++ b/.github/workflows/autogen-remote-changes.yml @@ -1,64 +1,92 @@ name: Auto-Update SDK -# on: -# schedule: -# - cron: "0 0 * * 1" # Runs every Monday at midnight -# workflow_dispatch: # Allows manual triggering of the workflow - -on: [push, pull_request] +on: + schedule: + - cron: "0 0 * * 1" # Runs every Monday at midnight + workflow_dispatch: # Allows manual triggering of the workflow jobs: update-sdk: runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] steps: - - name: Checkout repository + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + - name: Install OpenAPI Generator CLI + run: npm install @openapitools/openapi-generator-cli -g + - name: Install dependencies run: | - git clone https://github.com/${{ github.repository }} repo - cd repo - git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@users.noreply.github.com" + python -m pip install --upgrade pip + pip install -r requirements.txt - name: Pull and generate SDK - run: | - cd repo - make gen-openapi-remote + run: make gen-openapi-remote-for-ci - name: Check for changes + id: check_changes run: | - cd repo if git diff --quiet; then echo "changes=false" >> $GITHUB_ENV else echo "changes=true" >> $GITHUB_ENV fi + - name: Set up Git + if: env.changes == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" - name: Commit changes if: env.changes == 'true' run: | - cd repo - git checkout -b auto-update-sdk || git checkout auto-update-sdk + BRANCH_NAME="auto-update-sdk-$(date +'%Y-%m-%d-%H-%M-%S')" + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV + git checkout -b $BRANCH_NAME || git checkout $BRANCH_NAME git add . git commit -m "Auto-update SDK on $(date +'%Y-%m-%d')" - name: Push changes if: env.changes == 'true' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: git push --force --set-upstream origin $BRANCH_NAME + - name: Install GitHub CLI + if: env.changes == 'true' run: | - cd repo - git push --force --set-upstream origin auto-update-sdk - - name: Create a pull request + sudo apt-get update + sudo apt-get install -y gh + - name: Check for existing pull request if: env.changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + id: check_pr + run: | + PR_EXISTS=$(gh pr list --search "Auto-update SDK" --base main --state open --json number -q '.[0].number') + if [[ -n "$PR_EXISTS" ]]; then + echo "pr_exists=true" >> $GITHUB_ENV + echo "PR_NUMBER=$PR_EXISTS" >> $GITHUB_ENV + else + echo "pr_exists=false" >> $GITHUB_ENV + fi + - name: Create a pull request + if: env.changes == 'true' && env.pr_exists == 'false' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PR_TITLE="Auto-update SDK on $(date +'%Y-%m-%d')" - PR_BODY="This pull request was automatically created by GitHub Actions to update the SDK." - curl -H "Authorization: token $GITHUB_TOKEN" \ - -X POST \ - -H "Content-Type: application/json" \ - -d @- \ - https://api.github.com/repos/${{ github.repository }}/pulls < api/openapi.yaml gen-openapi: $(OPENAPI_GEN) gen-openapi-remote: - curl https://app.opal.dev/openapi.yaml > api/openapi.yaml - $(OPENAPI_GEN) \ No newline at end of file + $(PULL_REMOTE_OPENAPI) + $(OPENAPI_GEN) +gen-openapi-remote-for-ci: + $(PULL_REMOTE_OPENAPI) + $(OPENAPI_GEN_CI) diff --git a/config.json b/config.json index f1715c3..617349e 100644 --- a/config.json +++ b/config.json @@ -1 +1,8 @@ -{"enumClassPrefix": true, "packageName": "opal", "gitHost": "github.com", "gitUserId": "opalsecurity", "gitRepoId": "opal-python", "disallowAdditionalPropertiesIfNotPresent":false} +{ + "enumClassPrefix": true, + "packageName": "opal", + "gitHost": "github.com", + "gitUserId": "opalsecurity", + "gitRepoId": "opal-python", + "disallowAdditionalPropertiesIfNotPresent": false +} diff --git a/requirements.txt b/requirements.txt index e51ba9f..67f7f68 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -urllib3 >= 1.25.3, < 2.1.0 -setuptools >= 21.0.0 -python_dateutil >= 2.5.3 +urllib3 >= 1.25.3, < 3.0.0 +python_dateutil >= 2.8.2 pydantic >= 2 typing-extensions >= 4.7.1 diff --git a/test-requirements.txt b/test-requirements.txt index bb38d82..e98555c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,6 @@ -pytest~=7.1.3 -pytest-cov>=2.8.1 -pytest-randomly>=3.12.0 -mypy>=1.4.1 -types-python-dateutil>=2.8.19 \ No newline at end of file +pytest >= 7.2.1 +pytest-cov >= 2.8.1 +tox >= 3.9.0 +flake8 >= 4.0.0 +types-python-dateutil >= 2.8.19.14 +mypy >= 1.5