Search code examples
githubgithub-actionssqlpackage

Github action workflow sqlpackage does not exist


I'm brand new to Github workflows, this is the first one I've properly tried. I'm trying to get the workflow to build my sqlserver project made in Azure on push to master, then deploy it onto my server to TestDB, however the action doesn't seem to be working at the last stage. It downloads sqlpackage to upload the dacpac to my database, but actually executing this is where it's going wrong, it says it doesn't exist. Is anyone able to help me out? Thanks!

deploy-db.yml:

name: Build and Deploy database to server

on:
  push:
    branches: [ "master" ]

env:
  DATABASE_PROJECT_DIR: 'db'
  DB_DACPAC_NAME: db-dacpac

jobs:
  build:
    name: Build schema
    runs-on: windows-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Add msbuild to PATH
      uses: microsoft/[email protected]

    - name: Install .NET Framework 4.8 Developer Pack
      run: |
        choco install netfx-4.8-devpack -y

    - name: Build .dacpac
      run: msbuild ${{ env.DATABASE_PROJECT_DIR }}/db.sqlproj /p:Configuration=Release

    - name: Upload .dacpac Build Artifact
      id: build_output
      uses: actions/[email protected]
      with:
        name: ${{ env.DB_DACPAC_NAME }}
        path: ${{ env.DATABASE_PROJECT_DIR }}/bin/Release/db.dacpac

  deploy:
    needs: build
    name: Upload to server
    runs-on: ubuntu-latest
    steps:
    - name: Download .dacpac Artifact
      uses: actions/download-artifact@v4
      with:
        name: ${{ env.DB_DACPAC_NAME }}

    - name: Cache sqlpackage
      uses: actions/cache@v3
      with:
        path: sqlpackage
        key: sqlpackage-${{ runner.os }}-${{ hashFiles('sqlpackage.zip') }}

    - name: Install sqlpackage
      if: steps.cache.outputs.cache-hit != 'true'
      run: |
        wget https://aka.ms/sqlpackage-linux -O sqlpackage.zip
        unzip sqlpackage.zip -d sqlpackage
        chmod +x sqlpackage/sqlpackage
        sudo mv sqlpackage/sqlpackage /usr/local/bin/

    - name: Verify sqlpackage
      run: |
        ls -l /usr/local/bin/sqlpackage
        file /usr/local/bin/sqlpackage

    - name: Deploy DACPAC to TestDB
      run: |
        /usr/local/bin/sqlpackage /Action:Publish \
                   /SourceFile:./${{ env.DB_DACPAC_NAME }}/db.dacpac \
                   /TargetServerName:${{ secrets.DB_SERVER }} \
                   /TargetDatabaseName:TestDB\
                   /TargetUser:${{ secrets.DB_USER }} \
                   /TargetPassword:${{ secrets.DB_PASSWORD }} \
                   /Diagnostics:true

Run /usr/local/bin/sqlpackage /Action:Publish \
The application to execute does not exist: '/usr/local/bin/sqlpackage.dll'.
Error: Process completed with exit code 154.

During the Install sqlpackage stage, this appears in the log:

inflating: sqlpackage/sqlpackage
inflating: sqlpackage/sqlpackage.deps.json
inflating: sqlpackage/sqlpackage.dll
inflating: sqlpackage/sqlpackage.pdb
inflating: sqlpackage/sqlpackage.runtimeconfig.json
inflating: sqlpackage/sqlpackage.xml

and the log of the verification stage just after it

Run ls -l /usr/local/bin/sqlpackage
-rwxr-xr-x 1 runner docker 72520 Jun 20 21:30 /usr/local/bin/sqlpackage
/usr/local/bin/sqlpackage: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=d443991f54bcb9d02797daed79a3b5b1f7bdd004, stripped

which shows that sqlpackage is definitely there as an ELF executable. I did also try manually invoking the DLL, it didn't say that it didn't exist, it just said I can't execute a raw dll.

I don't know much about dll's, but from what the error tells me, it's looking for the DLL outside of the executable, but when I try to reference it, it doesn't like that. Any help would be greatly appreciated!


Solution

  • You need to set PATH using $GITHUB_PATH like this (no need to mv the executable):

    echo "$PWD/sqlpackage" >> "$GITHUB_PATH"
    

    Here's the complete example:

    name: install_sqlpackage
    
    on: workflow_dispatch
    
    jobs:
      ci:
        runs-on: ubuntu-latest
    
        steps:
        - name: Install sqlpackage
          run: |
            wget https://aka.ms/sqlpackage-linux -O sqlpackage.zip
            unzip sqlpackage.zip -d sqlpackage
            chmod +x sqlpackage/sqlpackage
            echo "$PWD/sqlpackage" >> "$GITHUB_PATH"
    
        - name: Check sqlpackage
          run: sqlpackage -version
    

    Output:

    output