PipelinesToActions

Azure Pipelines to GitHub Actions

Use this guidance to rewrite Azure Pipelines (Build and Release) Tasks on GitHub Actions. To check each implmentation, please access PipelineToActions GitHub Pages.

Table of contents

A

Azure CLI

Azure Pipelines

Azure CLI

Azure CLI

steps:
- task: AzureCLI@2
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: '[Azure Subscription]'
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
     az account show
     az storage -h

GitHub Actions

Azure CLI

    - name: Azure Login
      uses: Azure/login@v1.1
      with:
        creds: ${{secrets.AZURE_CREDENTIALS}}

    - name: Azure CLI script
      uses: azure/CLI@v1
      with:
        azcliversion: 2.0.72
        inlineScript: |
          az account show
          az storage -h 

Azure SQL

Azure Pipelines

Azure SQL DacpacTask

Azure SQL

steps:
- task: SqlAzureDacpacDeployment@1
  displayName: 'Azure SQL DacpacTask'
  inputs:
    azureSubscription: '[Subscription Name]'
    ServerName: '$(SQLServer)'
    DatabaseName: '$(SQLDatabase)'
    SqlUsername: '$(Login)'
    SqlPassword: '$(Pwd)'
    DacpacFile: '$(System.DefaultWorkingDirectory)/_[Project Name]/drop/[Project Name]/bin/Release/[Project Name].dacpac'

GitHub Actions

Azure SQL Deploy

- name: Azure SQL Deploy
  uses: Azure/sql-action@v1
  with:
    server-name: ${{secrets.SQL_SERVERNAME}}
    connection-string: ${{secrets.AZURE_SQL_CONNECTION_STRING}}
    dacpac-package: ./[Project Name]/bin/${{env.buildConfiguration}}/[Project Name].dacpac

Azure Web App

Azure Pipelines

Azure Web App

Azure Web App

steps:
- task: AzureWebApp@1
  displayName: 'Azure Web App'
  inputs:
    azureSubscription: '[Subscription]'
    appType: webApp
    appName: [App Name]
    package: '$(System.DefaultWorkingDirectory)\**\*.zip'

GitHub Actions

Azure Web App

    - name: Azure Login
      uses: Azure/login@v1.1
      with:
        creds: ${{secrets.AZURE_CREDENTIALS}}

    - name: Deploy to Azure Web App
      uses: azure/webapps-deploy@v1
      with:
        app-name: '[App Name]'
        package: ${{env.DOTNET_ROOT}}/myapp 

D

Docker

Azure Pipelines

Docker task

Docker (build) Docker (push)

steps:
- task: Docker@2
  displayName: Login to Docker Hub
  inputs:
    command: login
    containerRegistry: dockerHubServiceConnection
- task: Docker@2
  displayName: Build and Push
  inputs:
    command: buildAndPush
    repository: someUser/contoso
    tags: |
      tag1
      tag2

GitHub Actions

Build and push Docker images

    uses: docker/build-push-action@v1
    with:
      username: ${{secrets.DOCKER_USERNAME}}
      password: ${{secrets.DOCKER_PASSWORD}}
      repository: myorg/myrepository
      tags: latest

DotNetCore

Azure Pipelines

.Net Core CLI

.Net Core CLI (restore) .Net Core CLI (build) .Net Core CLI (test)

steps:
- task: DotNetCoreCLI@2
  displayName: Restoring .Net packages
  inputs:
    command: 'restore'
- task: DotNetCoreCLI@2
  displayName: Building code
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
  displayName: Running unit tests
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

GitHub Actions

.Net Core SDK

    # Install .Net Core SDK: https://github.com/actions/setup-dotnet
    - name: Setup .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: 3.1.101
    - name: Install dependencies
      run: dotnet restore
    - name: Build
      run: dotnet build --configuration Release --no-restore
    - name: Test
      run: dotnet test --no-restore --verbosity normal

I

IIS web app deploy

Azure Pipelines

IIS web app deploy

MS Build MS Deploy

#MSBuild
steps:
- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

#MSDeploy
steps:
- task: IISWebAppDeploymentOnMachineGroup@0
  displayName: 'Deploy IIS Website/App: '
  inputs:
    WebSiteName: $(WebSiteName)

GitHub Actions

Setup Nuget.exe

Setup MSBuild.exe

    env:
      Solution_Name: 'mySoltion.sln'                      
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
      WebSiteName: 'mySite'
      zipName: 'mySolution.zip'
    
    steps:
      
    - name: Checkout
      uses: actions/checkout@v2      
      
    - name: Setup Nuget.exe
      uses: warrenbuckley/Setup-Nuget@v1
      
    - name: Restore Packages
      run: nuget restore $env:Solution_Name
  
    - name: Setup MSbuild.exe
      uses: warrenbuckley/Setup-MSBuild@v1
      
    - name: Build using MSBuild
      run: msbuild $env:Solution_Name /p:platform=$env:buildPlatform /p:Configuration=$env:buildConfiguration /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation='C:\myapp'
          
    - name: Run MSDeploy.exe
      run: msdeploy -verb:sync -source:package=C:\myapp\${{ env.zipName }} -dest:auto -setParam:name=`'IIS Web Application Name`',value=$env:WebSiteName -enableRule:DoNotDeleteRule

M

MSBuild

Azure Pipelines

MSBuild

MS Build

steps:
- task: MSBuild@1
  displayName: 'Build solution **/*.sln'
  inputs:
    platform: '$(BuildPlatform)'
    configuration: '$(Buildconfiguration)'
    msbuildArguments: '/p:OutputPath=$(Build.ArtifactStagingDirectory)'

GitHub Actions

MSBuild

    # Add  MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
    - name: Setup MSBuild.exe
      uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16
      
    # Create the app package by building and packaging the Windows Application Packaging project
    - name: Run Msbuild
      run: msbuild $env:Solution_Name /p:platform=$env:buildPlatform /p:Configuration=$env:buildConfiguration

P

Publish Artifact

Azure Pipelines

Publish Artifact

Publish Artifacts

steps:
- task: CopyFiles@2
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '*.yml'
    TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
    inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

GitHub Actions

Upload a Build Artifact

- name: Copy JMeter Files
  shell: pwsh
  run: |
    Copy-Item -Path ./deploy.yml -Destination $ -Force
- name: Publish Artifacts
uses: actions/upload-artifact@v1.0.0
with:
    name: drop
    path: $

V

Version JSON File

Azure Pipelines

Manifest Versioning Build Tasks

Version JSON File

steps:
- task: VersionJSONFile@2
    inputs:
      Path: '$(Build.SourcesDirectory)'
      recursion: True
      VersionNumber: '$(Build.BuildNumber)'
      useBuildNumberDirectly: False
      VersionRegex: '\d+\.\d+\.\d+\.\d+'
      versionForJSONFileFormat: '{1}.{2}.{3}'
      FilenamePattern: 'package.json'
      OutputVersion: 'OutputedVersion'

GitHub Actions

Apply Version to JSON file

- name: Apply Version to JSON file
  uses: rfennell/JSONFileVersioner@v1
  with:
    path: 'testdata'
    field: 'version'
    VersionNumber: '1.2.3'
    filenamepattern: '.json' 
    recursion: 'true'

VSBuild

Azure Pipelines

VSBuild

VS Build

steps:
- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '**\*.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

GitHub Actions

VSBuild

    # Add  MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
    - name: Setup MSBuild.exe
      uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16
      
    # Create the app package by building and packaging the Windows Application Packaging project
    - name: Run Msbuild
      run: msbuild $env:Solution_Name /p:platform=$env:buildPlatform /p:Configuration=$env:buildConfiguration

References

Contribute

Contributions to Pipelines to GitHub Actions are welcome. Please fork this repo.

Include Tasks