github actions faqs
Working with different stage does not mean you have access to the previous stage that download code repository
Github action different stage that runs will not have access to code downloaded or checkout from previous. Something that tripped me while trying to reuse create a reusable workflow template.
Stages that does not specified "needs" it will run one after another (sequentially)
Here we have build and containerize stage. without specifying needs, build will run first and then containerize.
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: '${{ inputs.dotnet-version }}'
containerize:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
How do you create a package from a dotnet build?
You can refer to the following code to publish a nuget package. Every new runs will set the version number accordingly. Of course, you can specify your own version number as well.
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set version from pipeline run
run: echo "PACKAGE_VERSION=1.0.${{ github.run_number }}" >> $GITHUB_ENV
- name: Setup dotnet and package endpoint
uses: actions/setup-dotnet@v4
with:
dotnet-version: '${{ inputs.dotnet-version }}'
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: debug packages
run: ls -al ${{ github.workspace }}
- name: Restore build and package all .NET projects
run: |
for proj in $(find . -name "*.csproj"); do
echo "Building $proj"
dotnet restore "$proj"
dotnet build "$proj" --no-restore --configuration Release
dotnet pack "$proj" --configuration Release --no-build -p:Version=${{ env.PACKAGE_VERSION }} --output ./nupkgs
done
- name: debug packages
run: ls -al ${{ github.workspace }}
- name: Publish to GitHub Packages
run: dotnet nuget push ./nupkgs/*.nupkg --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
Comments