Skip to content

use per run token

use per run token #61

Workflow file for this run

# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
name: 'Tasks CI'
on:
push:
branches: [ "main", "gitversion" ]
paths:
- '.github/workflows/tasks-*.yml'
- 'src/Tasks/**'
- 'src/TasksApi/**'
pull_request:
branches: [ "main" ]
paths:
- '.github/workflows/tasks-*.yml'
- 'src/Tasks/**'
- 'src/TasksApi/**'
workflow_dispatch:
permissions:
statuses: write
checks: write
packages: write
# https://docs.github.com/en/actions/learn-github-actions/variables
env:
project: Tasks
project-file: src/Tasks/Tasks.csproj
project-package-id: Boster.Training.Tasks.DotNet
configuration: Release
build-output: ${{ github.workspace }}/build
package-output: ${{ github.workspace }}/packaging
jobs:
build:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest] # [ubuntu-latest, windows-latest]
dotnet: ['7.x']
include:
- os: ubuntu-latest
dotnet: '7.x'
package: true # ${{ (github.event_name == 'pull_request' && github.event.action != 'closed') }}
outputs:
# zip_package_artifact: ${{ steps.create-zip-package.outputs.package_filename }}
nuget_package_artifact: ${{ steps.create-nuget-package.outputs.package_filename }}
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Get Build Information
id: build-info
shell: pwsh
run: |
$versionPrefix = Get-Date -Format "yyyy.MM.dd"
$runNumber = "${{ github.run_number }}"
echo "version=$versionPrefix.$runNumber"
echo "version=2023.11.25.55" >> $env:GITHUB_OUTPUT
- name: Check Information
shell: pwsh
run: |
echo ${{ steps.build-info.outputs.version }}
- name: Restore dependencies
shell: pwsh
run: dotnet restore ${{ env.project-file }}
- name: Build
id: build
shell: pwsh
run: |
dotnet build ${{ env.project-file }} --no-restore --configuration ${{ env.configuration }} -p:Version=${{ steps.build-info.outputs.version }} --output ${{ env.build-output }}/${{ env.project }}
[System.Reflection.Assembly]::LoadFrom("${{ env.build-output }}/${{ env.project }}/${{ env.project }}.dll").GetName().Version
echo "package_id=${{ env.project-package-id }}" >> $env:GITHUB_OUTPUT
echo "output=${{ env.build-output }}/${{ env.project }}" >> $env:GITHUB_OUTPUT
echo "output_assembly=${{ env.build-output }}/${{ env.project }}/${{ env.project }}.dll" >> $env:GITHUB_OUTPUT
- name: Test
shell: pwsh
run: |
dotnet test ${{ steps.build.outputs.output_assembly }} --no-build --verbosity normal --logger "trx;LogFileName=test-results.trx"
- name: Test Report
uses: dorny/test-reporter@v1
if: always()
with:
name: .Net Unit Tests
path: "**/test-results.trx"
reporter: dotnet-trx
fail-on-error: true
- name: Create a NuGet package
id: create-nuget-package
if: ${{ matrix.package }}
shell: pwsh
run: |
dotnet pack ${{ env.project-file }} --configuration ${{ env.configuration }} --no-build --no-restore -p:PackageId=${{ steps.build.outputs.package_id }} -p:PackageVersion=${{ steps.build-info.outputs.version }} -p:Authors="Dave Boster" --output ./packaging -p:OutputPath=${{ steps.build.outputs.output }}
echo "package_filename=${{ steps.build.outputs.package_id }}.${{ steps.build-info.outputs.version }}.nupkg" >> $env:GITHUB_OUTPUT
echo "package_file_path=${{ env.package-output }}/${{ steps.build.outputs.package_id }}.${{ steps.build-info.outputs.version }}.nupkg" >> $env:GITHUB_OUTPUT
- name: Prep packages
shell: pwsh
run: |
dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Push package to GitHub packages
shell: pwsh
run: |
dotnet nuget push ./packaging/${{ steps.create-nuget-package.outputs.package_filename }} --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate
# - name: Create a Zip package 🐙
# if: ${{ matrix.package }}
# id: create-zip-package
# uses: OctopusDeploy/create-zip-package-action@v3
# with:
# package_id: ${{ steps.build.outputs.package_id }}
# version: ${{ steps.build-info.outputs.version }}
# output_folder: './packaging'
# base_path: ${{ steps.build.outputs.output }}
# files: |
# **/*.*
# - name: Create a NuGet package
# id: create-nuget-package
# if: ${{ matrix.package }}
# shell: pwsh
# run: |
# dotnet pack ${{ env.project-file }} --configuration ${{ env.configuration }} --no-build --no-restore -p:PackageId=${{ steps.build.outputs.package_id }} -p:PackageVersion=${{ steps.build-info.outputs.version }} -p:Authors="Dave Boster" --verbosity detailed --output ./packaging -p:OutputPath=${{ steps.build.outputs.output }}
# echo "package_filename=${{ steps.build.outputs.package_id }}.${{ steps.build-info.outputs.version }}.nupkg" >> $env:GITHUB_OUTPUT
# echo "package_file_path=${{ env.package-output }}/${{ steps.build.outputs.package_id }}.${{ steps.build-info.outputs.version }}.nupkg" >> $env:GITHUB_OUTPUT
# - name: Create a NuGet package 🐙
# if: ${{ matrix.publish }}
# id: create-nuget-package
# uses: OctopusDeploy/create-nuget-package-action@v3
# with:
# package_id: ${{ steps.build.outputs.package_id }}
# version: ${{ steps.build-info.outputs.version }}
# output_folder: './packaging'
# base_path: ${{ steps.build.outputs.output }}
# files: |
# **/*.*
# nuspec_description: description
# nuspec_authors: |
# Dave Boster
# - name: Upload Zip package to build artifacts 🗳️
# if: ${{ matrix.package }}
# uses: actions/upload-artifact@v3
# with:
# name: ${{ steps.create-zip-package.outputs.package_filename }}
# path: ${{ steps.create-zip-package.outputs.package_file_path }}
# retention-days: 1
# - name: Upload NuGet package to build artifacts 🗳️
# if: ${{ matrix.package }}
# uses: actions/upload-artifact@v3
# with:
# name: ${{ steps.create-nuget-package.outputs.package_filename }}
# path: ${{ steps.create-nuget-package.outputs.package_file_path }}
# retention-days: 1
# publish:
# # if: github.event_name == 'pull_request' && github.event.action == 'closed'
# runs-on: ubuntu-latest
# needs: build
# name: Publish Packages
# steps:
# - name: Download zip package
# uses: actions/download-artifact@v3
# with:
# name: ${{ needs.build.outputs.zip_package_artifact }}
# path: './packaging'
# - name: Download NuGet package
# uses: actions/download-artifact@v3
# with:
# name: ${{ needs.build.outputs.nuget_package_artifact }}
# path: './packaging'
# - name: Prep packages
# shell: pwsh
# run: |
# dotnet nuget add source --username ${{ github.repository_owner }} --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
# - name: Push package to GitHub packages
# shell: pwsh
# run: |
# dotnet nuget push ./packaging/${{ needs.build.outputs.nuget_package_artifact }} --api-key ${{ secrets.GITHUB_TOKEN }} --source "github"
# tests_e2e:
# uses: ./.github/workflows/tests-e2e-playwright.yml