|
| 1 | +name: Update Wrapper |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + # runs every day at 02:23 UTC |
| 5 | + - cron: '23 2 * * *' |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + update: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v2 |
| 14 | + - name: Setup java |
| 15 | + uses: actions/setup-java@v2 |
| 16 | + with: |
| 17 | + java-version: 17 |
| 18 | + distribution: 'zulu' |
| 19 | + cache: 'maven' |
| 20 | + - name: Get latest fixed open api definition |
| 21 | + id: latest-openapi |
| 22 | + uses: actions/github-script@v6 |
| 23 | + with: |
| 24 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 25 | + result-encoding: string |
| 26 | + script: | |
| 27 | + const response = await github.rest.repos.getLatestRelease({ |
| 28 | + owner: 'sonallux', |
| 29 | + repo: 'spotify-web-api', |
| 30 | + }); |
| 31 | + const assetName = 'fixed-spotify-open-api.yml'; |
| 32 | + const asset = response.data.assets.find(asset => asset.name === assetName); |
| 33 | + const browserDownloadUrl = asset?.browser_download_url; |
| 34 | + if (!browserDownloadUrl) { |
| 35 | + core.setFailed('Latest release did not contain the correct asset!'); |
| 36 | + } |
| 37 | + return browserDownloadUrl; |
| 38 | + - name: Download Spotify's OpenAPI |
| 39 | + run: wget -O spotify-web-api-java-generator/fixed-spotify-open-api.yml ${{ steps.latest-openapi.outputs.result }} |
| 40 | + - name: Build generator |
| 41 | + run: ./mvnw -B -DskipTests package -Pcli |
| 42 | + - name: Generate Java wrapper |
| 43 | + run: ./generate-java-wrapper.sh |
| 44 | + - name: Create Pull Request |
| 45 | + id: cpr |
| 46 | + uses: peter-evans/create-pull-request@v3 |
| 47 | + with: |
| 48 | + # Use a PAT so GitHub actions are triggered on the PR |
| 49 | + token: ${{ secrets.GH_REPO_TOKEN }} |
| 50 | + commit-message: 'Update to fixed-spotify-open-api.yml' |
| 51 | + branch: 'openapi-update' |
| 52 | + delete-branch: true |
| 53 | + base: main |
| 54 | + author: 'sonallux <13821543+sonallux@users.noreply.github.com>' |
| 55 | + title: 'Update to fixed-spotify-open-api.yml' |
| 56 | + body: | |
| 57 | + Automated update of `fixed-spotify-open-api.yml` |
| 58 | +
|
| 59 | + Generated by [this workflow run](https://github.com/sonallux/spotify-web-api-java/actions/runs/${{ github.run_id }}). |
| 60 | + - name: Check outputs |
| 61 | + run: 'echo "Pull Request ${{ steps.cpr.outputs.pull-request-operation }}: ${{ steps.cpr.outputs.pull-request-url }}"' |
| 62 | + - name: Comment on PR |
| 63 | + if: steps.cpr.outputs.pull-request-operation == 'created' |
| 64 | + uses: actions/github-script@v6 |
| 65 | + with: |
| 66 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 67 | + script: | |
| 68 | + github.rest.issues.createComment({ |
| 69 | + issue_number: ${{ steps.cpr.outputs.pull-request-number }}, |
| 70 | + owner: context.repo.owner, |
| 71 | + repo: context.repo.repo, |
| 72 | + body: "@sonallux fixed-spotify-open-api.yml has been updated!" |
| 73 | + }) |
0 commit comments