IFI Techsolutions

CI/CD pipeline for workflow automation using GitHub Actions.

Author – Shefali Kamble, Cloud Engineer Overview GitHub Actions is a CI/CD and general automation system introduced by GitHub. It is integrated right into GitHub and enabled by default in every GitHub repository. GitHub Actions help you automate tasks within your software development life cycle. It is event-driven, which means that we can run a […]

Author – Shefali Kamble, Cloud Engineer

Overview

GitHub Actions is a CI/CD and general automation system introduced by GitHub. It is integrated right into GitHub and enabled by default in every GitHub repository. GitHub Actions help you automate tasks within your software development life cycle. It is event-driven, which means that we can run a series of commands after a specified event has occurred.

How GitHub Actions are automated?

Every time someone creates a pull request for a repository, you can automatically run a command that executes a software testing script. An event then automatically triggers the workflow, which contains a job. The job then uses steps to control the order in which actions are run. These actions are the commands that automate your software testing.

Getting Started with GitHub Actions

Prerequisites

Workflow file overview

A workflow is defined by a YAML (.yml) file in the /.github/workflows/ path in your repository. This definition contains the various steps and parameters that make up the workflow.

Setting up the Workflow File

There are two ways to create a workflow file:

  1. Use the Deployment Center in Azure Portal
  2. Set up the workflow manually

Use the Deployment Center in Azure Portal

You can get started with GitHub Actions by using the App Service Deployment Center. This will automatically generate a workflow file based on your application stack and commit it to your GitHub repository in the correct directory.

  1. Go to Azure Portal and select your App service. In the left blade under Deployment select Deployment Center.
  2. In the source select GitHub and authorize your account.
  3. Fill in all the details under GitHub and Verify the configuration by clicking on Preview File and then click on Save.
  4. Go the GitHub repository and click on Actions tab, there you will find the running workflow. You can view all the tasks as it runs.

Once completed you can navigate to the Azure App Service URL and view the web page.

Set up a workflow manually

You can also deploy a workflow without using the Deployment Center. To do so, you will need to first generate deployment credentials.

Generate deployment credentials

A publish profile is an app-level credential. Set up your publish profile as a GitHub secret.

    1. Go to your app service in the Azure portal. On the Overview page, select Get Publish profile.
    2. Save the downloaded file. You’ll use the contents of the file to create a GitHub secret.Configure the GitHub secret
    3. In GitHub, browse your repository, select Settings > Secrets > Add a new secret.To use app-level credentials, paste the contents of the downloaded publish profile file into the secret’s value field. Name the secret AZURE_WEBAPP_PUBLISH_PROFILE.
    4. Create a new workflow file and paste in the code.
      name: .NET Core CI
      on: [push]
      env:
        AZURE_WEBAPP_NAME: your-app-name       # set this to your application’s name
        AZURE_WEBAPP_PACKAGE_PATH: ‘.’           # set this to the path to your web app project, defaults to the repository root
        DOTNET_VERSION: ‘3.1.x’                               # set this to the dot net version to use
      jobs:
        build:
          runs-on: ubuntu-latest
          steps:
            # Checkout the repo
            – uses: actions/checkout@main
            # Setup .NET Core SDK
            – name: Setup .NET Core
              uses: actions/setup-dotnet@v1
              with:
                dotnet-version: ${{ env.DOTNET_VERSION }}
            # Run dotnet build and publish
            – name: dotnet build and publish
              run: |
                dotnet restore
                dotnet build –configuration Release
                dotnet publish -c Release -o ‘${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp’
            # Deploy to Azure Web apps
            – name: ‘Run Azure webapp deploy action using publish profile credentials’
              uses: azure/webapps-deploy@v2
              with:
                app-name: ${{ env.dotnetwebapp59 }}                                                    # Replace with your app name
                publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE  }} # Define secret variable in repository settings as per action documentation
                package: ‘${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp’

    5. Commit the new file and enter the name optionally.
    6. Go to the Actions tab and see the workflow runs.
    7. Browse the website URL through the Azure Portal or you can even find it at the end of job completion in the workflow run.

Hope this article was helpful and will guide you to automate your workflow using GitHub Actions. You can post your thoughts/queries in the comment section.

Leave a Reply

Subscribe to our knowledge library.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare