This post is going to take the GitHub Actions Workflow we set up in the last post and add a couple of steps that will provide us with access to our application’s binaries. If you are new to this series the following post will catch you up if needed.
GitHub: Import an Azure DevOps Repo
GitHub: Use Actions to build ASP.NET Core Application
Edit the Workflow
Our first step is to get back to the Workflow we want to edit. At the top of the repo click Actions.
On the left side of the screen select the specific Workflow, .NET Core in this case. Now that the list is filtered to just the Workflow we are interested in select the three dots on the most recent run and then click View workflow file.
On the next screen click the pencil above the Workflow file to edit the Workflow.
Add the end of the file adds a call to the .NET CLI to publish. The following is the full file and the last two lines are the publish step.
name: .NET Core on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/[email protected] - name: Setup .NET Core uses: actions/[email protected] 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 - name: Publish run: dotnet publish
Click the Start commit button and commit the change to the branch of your choice. I committed the change directly to master which triggered the Workflow to run. From the logs of the Workflow, you can see that the publish step executed successfully.
Publish Build Artifacts
Now that we have the two web applications publishing we need a way to get the file for the applications. To do this we are going to use the Upload Artifacts Action. I used the output of the Publish step above to find the path to the publish folder for each application and then used an Upload Artifacts Action for each application. The following are the two steps added to the bottom of our existing Workflow.
- name: Upload WebApp1 Build Artifact uses: actions/[email protected] with: name: WebApp1 path: /home/runner/work/Playground/Playground/src/WebApp1/bin/Debug/netcoreapp3.1/publish/ - name: Upload WebApp2 Build Artifact uses: actions/[email protected] with: name: WebApp2 path: /home/runner/work/Playground/Playground/src/WebApp2/bin/Debug/netcoreapp3.1/publish/
After checking in the changes let the Workflow run. Once complete if you click on the details of the Workflow run you will see it now has Artifacts that can be downloaded.
We now have a Workflow that results in files we could actually deploy on top of verifying that the applications builds and the tests pass. I hope this has given you a good jumping-off point to build your own Workflows. We have only scratched the surface of what can be done with GitHub Actions and I’m looking forward to seeing what else we can do.
Also published on Medium.
1 thought on “GitHub: Use Actions to Publish Artifacts”
Thanks for this article. Note that in the “path” you can specify a relative path — this may be less fragile if they change the directory name. So in your case I think you can use path: src/WebApp2/bin/Debug/netcoreapp3.1/publish/
I am making a demo repo that you might find interesting — it is using Gitflow and my intent is to get to the point where final releases are published to GitHub. https://github.com/bcr/dotnet-actions-gitflow