Skip to content

Commit

Permalink
Create GitHub action to keep ManagedBatchParser dependency up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrosenberg committed Feb 8, 2025
1 parent 58ea619 commit aae9b7e
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 2 deletions.
142 changes: 142 additions & 0 deletions .github/workflows/update-managed-batch-parser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
name: Update ManagedBatchParser

on:
schedule:
- cron: "50 11 * * 0" # 11:50 am UTC, every Sunday

defaults:
run:
shell: bash

jobs:
get_versions:
name: Check current and latest ManagedBatchParser versions
runs-on: ubuntu-latest

outputs:
current: ${{ steps.get_current.outputs.current }}
latest: ${{ steps.output_jq.outputs.latest }}
download_url: ${{ steps.output_jq.outputs.url }}

steps:
- id: create_dirs
name: Create working directories
run: |
mkdir repo
mkdir working
- id: checkout
uses: actions/checkout@v4
with:
path: repo

- id: get_current
name: Get currently-used version from version.txt
working-directory: repo
run: echo "current=$(cat src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser/version.txt)" >> "$GITHUB_OUTPUT"

# Get sqltoolsservice release metadata,
# store in a file for later processing using JQ
- id: curl_sqltoolsservice
name: Get latest release metadata for sqltoolsservice
working-directory: working
run: curl https://api.github.com/repos/microsoft/sqltoolsservice/releases/latest | tee curl.txt

- id: get_latest
name: Get latest version number from release metadata
uses: direct-actions/jq@v1
with:
filter: '.tag_name'
input-files: working/curl.txt
raw-output: true

- id: get_download_url
name: Get download URL from release metadata
uses: direct-actions/jq@v1
with:
filter: '.assets[] | select(.content_type == "application/octet-stream") | select(.name | contains("ServiceLayer-linux-x64")) | .browser_download_url'
input-files: working/curl.txt
raw-output: true

- id: output_jq
name: Send parsed JSON data to output
run: |
echo "latest=${{ steps.get_latest.outputs.output }}" >> "$GITHUB_OUTPUT"
echo "url=${{ steps.get_download_url.outputs.output }}" >> "$GITHUB_OUTPUT"
compare_versions:
name: Compare versions
runs-on: ubuntu-latest
needs: get_versions

outputs:
needs_update: ${{ steps.compare_versions.outputs.needs_update }}

steps:
# Set 'needs_update' based on whether versions match
# (false if the versions match, true if they don't).
# The create_pr job is conditional on this value
- id: compare_versions
name: Compare versions and determine if update is needed
env:
CURRENT: ${{needs.get_versions.outputs.current}}
LATEST: ${{needs.get_versions.outputs.latest}}
run: |
needs_update=false
[[ "$CURRENT" != "$LATEST" ]] && needs_update=true
echo "needs_update=${needs_update}" >> "$GITHUB_OUTPUT"
create_pr:
name: Create pull request
runs-on: ubuntu-latest
needs:
- get_versions
- compare_versions
if: ${{ needs.compare_versions.outputs.needs_update == 'true' }}

steps:
- id: create_dirs
name: Create working directories
run: |
mkdir repo
mkdir working
- id: checkout
uses: actions/checkout@v4
with:
path: repo

- id: download
name: Download release tarball
working-directory: working
env:
DOWNLOAD_URL: ${{needs.get_versions.outputs.download_url}}
run: wget --output-document release.tar.gz "$DOWNLOAD_URL"

- id: set_latest
env:
LATEST: ${{needs.get_versions.outputs.latest}}
working-directory: working
run: |
tar \
--extract \
--file=release.tar.gz \
--overwrite \
Microsoft.SqlTools.ManagedBatchParser.dll
cp \
Microsoft.SqlTools.ManagedBatchParser.dll \
../repo/src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser
echo "$LATEST" > ../repo/src/DacpacTool/Microsoft.SqlTools.ManagedBatchParser/version.txt
- id: create_pr
name: Create pull request
uses: peter-evans/create-pull-request@v7
with:
path: repo
title: Update ManagedBatchParser version to ${{needs.get_versions.outputs.latest}}
commit-message: Update ManagedBatchParser version to ${{needs.get_versions.outputs.latest}}
body: Automated changes by [Update ManagedBatchParser action](https://github.com/rr-wfm/MSBuild.Sdk.SqlProj/blob/master/.github/workflows/update-managed-batch-parser.yml)
branch: actions/managed-batch-parser-${{needs.get_versions.outputs.latest}}
delete-branch: true
4 changes: 2 additions & 2 deletions src/DacpacTool/DacpacTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

<!-- References to Microsoft.SqlTools.ManagedBatchParser -->
<ItemGroup>
<Content Include="Microsoft.SqlTools.ManagedBatchParser.dll">
<Content Include="Microsoft.SqlTools.ManagedBatchParser/Microsoft.SqlTools.ManagedBatchParser.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<PackageReference Include="Microsoft.SqlServer.SqlManagementObjects" Version="172.52.0" />
<Reference Include="Microsoft.SqlTools.ManagedBatchParser">
<HintPath>Microsoft.SqlTools.ManagedBatchParser.dll</HintPath>
<HintPath>Microsoft.SqlTools.ManagedBatchParser/Microsoft.SqlTools.ManagedBatchParser.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0.20241218.1

0 comments on commit aae9b7e

Please sign in to comment.