|
| 1 | +name: Update ManagedBatchParser |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "50 11 * * 0" # 11:50 am UTC, every Sunday |
| 6 | + |
| 7 | +defaults: |
| 8 | + run: |
| 9 | + shell: bash |
| 10 | + |
| 11 | +jobs: |
| 12 | + get_versions: |
| 13 | + name: Check current and latest ManagedBatchParser versions |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + outputs: |
| 17 | + current: ${{ steps.get_current.outputs.current }} |
| 18 | + latest: ${{ steps.output_jq.outputs.latest }} |
| 19 | + download_url: ${{ steps.output_jq.outputs.url }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - id: create_dirs |
| 23 | + name: Create working directories |
| 24 | + run: | |
| 25 | + mkdir repo |
| 26 | + mkdir working |
| 27 | +
|
| 28 | + - id: checkout |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + path: repo |
| 32 | + |
| 33 | + - id: get_current |
| 34 | + name: Get currently-used version from version.txt |
| 35 | + working-directory: repo |
| 36 | + run: echo "current=$(cat src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser/version.txt)" >> "$GITHUB_OUTPUT" |
| 37 | + |
| 38 | + # Get sqltoolsservice release metadata, |
| 39 | + # store in a file for later processing using JQ |
| 40 | + - id: curl_sqltoolsservice |
| 41 | + name: Get latest release metadata for sqltoolsservice |
| 42 | + working-directory: working |
| 43 | + run: curl https://api.github.com/repos/microsoft/sqltoolsservice/releases/latest | tee curl.txt |
| 44 | + |
| 45 | + - id: get_latest |
| 46 | + name: Get latest version number from release metadata |
| 47 | + uses: direct-actions/jq@v1 |
| 48 | + with: |
| 49 | + filter: '.tag_name' |
| 50 | + input-files: working/curl.txt |
| 51 | + raw-output: true |
| 52 | + |
| 53 | + - id: get_download_url |
| 54 | + name: Get download URL from release metadata |
| 55 | + uses: direct-actions/jq@v1 |
| 56 | + with: |
| 57 | + filter: '.assets[] | select(.content_type == "application/octet-stream") | select(.name | contains("ServiceLayer-linux-x64")) | .browser_download_url' |
| 58 | + input-files: working/curl.txt |
| 59 | + raw-output: true |
| 60 | + |
| 61 | + - id: output_jq |
| 62 | + name: Send parsed JSON data to output |
| 63 | + run: | |
| 64 | + echo "latest=${{ steps.get_latest.outputs.output }}" >> "$GITHUB_OUTPUT" |
| 65 | + echo "url=${{ steps.get_download_url.outputs.output }}" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + compare_versions: |
| 68 | + name: Compare versions |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: get_versions |
| 71 | + |
| 72 | + outputs: |
| 73 | + needs_update: ${{ steps.compare_versions.outputs.needs_update }} |
| 74 | + |
| 75 | + steps: |
| 76 | + # Set 'needs_update' based on whether versions match |
| 77 | + # (false if the versions match, true if they don't). |
| 78 | + # The create_pr job is conditional on this value |
| 79 | + - id: compare_versions |
| 80 | + name: Compare versions and determine if update is needed |
| 81 | + env: |
| 82 | + CURRENT: ${{needs.get_versions.outputs.current}} |
| 83 | + LATEST: ${{needs.get_versions.outputs.latest}} |
| 84 | + run: | |
| 85 | + needs_update=false |
| 86 | + [[ "$CURRENT" != "$LATEST" ]] && needs_update=true |
| 87 | + echo "needs_update=${needs_update}" >> "$GITHUB_OUTPUT" |
| 88 | +
|
| 89 | + create_pr: |
| 90 | + name: Create pull request |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: |
| 93 | + - get_versions |
| 94 | + - compare_versions |
| 95 | + if: ${{ needs.compare_versions.outputs.needs_update == 'true' }} |
| 96 | + |
| 97 | + steps: |
| 98 | + - id: create_dirs |
| 99 | + name: Create working directories |
| 100 | + run: | |
| 101 | + mkdir repo |
| 102 | + mkdir working |
| 103 | +
|
| 104 | + - id: checkout |
| 105 | + uses: actions/checkout@v4 |
| 106 | + with: |
| 107 | + path: repo |
| 108 | + |
| 109 | + - id: download |
| 110 | + name: Download release tarball |
| 111 | + working-directory: working |
| 112 | + env: |
| 113 | + DOWNLOAD_URL: ${{needs.get_versions.outputs.download_url}} |
| 114 | + run: wget --output-document release.tar.gz "$DOWNLOAD_URL" |
| 115 | + |
| 116 | + - id: set_latest |
| 117 | + env: |
| 118 | + LATEST: ${{needs.get_versions.outputs.latest}} |
| 119 | + working-directory: working |
| 120 | + run: | |
| 121 | + tar \ |
| 122 | + --extract \ |
| 123 | + --file=release.tar.gz \ |
| 124 | + --overwrite \ |
| 125 | + Microsoft.SqlTools.ManagedBatchParser.dll |
| 126 | +
|
| 127 | + cp \ |
| 128 | + Microsoft.SqlTools.ManagedBatchParser.dll \ |
| 129 | + ../repo/src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser |
| 130 | +
|
| 131 | + echo "$LATEST" > ../repo/src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser/version.txt |
| 132 | +
|
| 133 | + - id: create_pr |
| 134 | + name: Create pull request |
| 135 | + uses: peter-evans/create-pull-request@v7 |
| 136 | + with: |
| 137 | + path: repo |
| 138 | + title: Update ManagedBatchParser version to ${{needs.get_versions.outputs.latest}} |
| 139 | + commit-message: Update ManagedBatchParser version to ${{needs.get_versions.outputs.latest}} |
| 140 | + body: Automated changes by [Update ManagedBatchParser action](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj/blob/master/.github/workflows/update-managed-batch-parser.yml) |
| 141 | + branch: actions/managed-batch-parser-${{needs.get_versions.outputs.latest}} |
| 142 | + delete-branch: true |
0 commit comments