Python Torn APIv2 code generation via Torngen #7142
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Python Torn APIv2 code generation via Torngen | |
| on: | |
| schedule: | |
| - cron: "* * * * 1-5" | |
| workflow_dispatch: | |
| env: | |
| MIX_ENV: prod | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| jobs: | |
| generate: | |
| runs-on: ubuntu-22.04 | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| actions: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # Latest version | |
| - elixir: "1.18" | |
| otp: "27.2" | |
| steps: | |
| - name: Check out this repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Erlang and Elixir | |
| uses: erlef/setup-beam@v1 | |
| with: | |
| otp-version: ${{matrix.otp}} | |
| elixir-version: ${{matrix.elixir}} | |
| - name: Cache Mix dependencies | |
| uses: actions/cache@v3 | |
| id: cache-deps | |
| with: | |
| path: | | |
| deps | |
| _build | |
| key: | | |
| mix-${{ runner.os }}-${{matrix.elixir}}-${{matrix.otp}}-${{ hashFiles('**/mix.lock') }} | |
| restore-keys: | | |
| mix-${{ runner.os }}-${{matrix.elixir}}-${{matrix.otp}}- | |
| - run: cd torngen && rm -rf path schemas | |
| - run: cd torngen_ex && mix do deps.get --check-locked, deps.compile | |
| if: steps.cache-deps.outputs.cache-hit != 'true' | |
| - run: wget -U "torngen-gh-action" https://www.torn.com/swagger/openapi.json | |
| - run: cd torngen_ex && mix torngen.generate | |
| - run: pip install isort black | |
| - run: isort . && black . | |
| - name: Configure git identity | |
| run: | | |
| git config user.email "webmaster@deek.sh" | |
| git config user.name "dssecret" | |
| - name: Diff generated code and master | |
| id: diff | |
| run: | | |
| git fetch | |
| git add . | |
| CHANGED_FILES=$(git diff --name-only origin/master) | |
| if [ -z "$CHANGED_FILES" ]; then | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Exit if not different | |
| if: steps.diff.outputs.changed != 'true' | |
| run: | | |
| echo "No changed files" | |
| gh run cancel ${{ github.run_id }} | |
| gh run watch ${{ github.run_id }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - id: get_version | |
| run: cat torngen/VERSION && echo "version=$(cat torngen/VERSION)" >> $GITHUB_OUTPUT | |
| - name: Prepare branch for PR | |
| run: | | |
| # Check local branch | |
| if git show-ref --quiet refs/heads/torngen/auto; then | |
| git checkout torngen/auto | |
| else | |
| git checkout -b torngen/auto | |
| fi | |
| git commit -m "[torngen] Generated v${{ steps.get_version.outputs.version }}" | |
| git push -u origin --force torngen/auto | |
| - name: Create Pull Request | |
| run: | | |
| gh pr create --title "[torngen] Generated v${{ steps.get_version.outputs.version }}" \ | |
| --body "This PR contains autogenerated changes." \ | |
| --base master \ | |
| --head torngen/auto \ | |
| || gh pr edit torngen/auto --title "[torngen] Generated v${{ steps.get_version.outputs.version }}" --body "This PR contains autogenerated changes." |