Bitreader improvements (#124) #203
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
push: | |
branches: [main] | |
paths-ignore: | |
- "**.md" | |
pull_request: # do a dry-run in PRs | |
paths: | |
- ".github/workflows/Publish.yml" | |
- ".github/get_published_version.sh" | |
- ".github/get_current_version.sh" | |
env: | |
LANG: 'C.UTF-8' # necessary for grep on Windows | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
publish: | |
runs-on: ubuntu-22.04 | |
timeout-minutes: 10 | |
strategy: | |
matrix: | |
include: | |
- project: JBSnorro | |
workflowName: CI | |
- project: JBSnorro.Testing | |
workflowName: CI (JBSnorro.Testing) | |
env: | |
CSPROJ_PATH: '${{ matrix.project }}/${{ matrix.project }}.csproj' | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: JeroenBos/setup-nuget@v1.1 | |
with: | |
gh-pat: ${{ secrets.GH_PACKAGE_ACCESS_TOKEN }} | |
- name: Detect if version changed | |
id: version-check | |
run: | | |
current_version=$(bash .github/get_current_version.sh "${CSPROJ_PATH}" | xargs) | |
echo "current_version: \"$current_version\"" | |
if ! [[ "$current_version" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then | |
echo "Error: An invalid current version was found" | |
exit 1 | |
fi | |
published_version=$(bash .github/get_published_version.sh "$PROJECT" | xargs) | |
echo "published_version: \"$published_version\"" | |
if ! [[ "$published_version" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then | |
echo "Error: An invalid published version was found" | |
exit 1 | |
fi | |
if [[ "$current_version" == "$published_version" ]]; then | |
echo "Up-to-date" | |
else | |
echo "changed=true" >> $GITHUB_OUTPUT | |
echo "new-version=$current_version" >> $GITHUB_OUTPUT | |
echo "Publishing" | |
fi | |
env: | |
PROJECT: ${{ matrix.project }} | |
- name: Setup .NET Core | |
if: steps.version-check.outputs.changed == 'true' | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
- name: Create local Package Source | |
if: steps.version-check.outputs.changed == 'true' | |
run: | | |
TempPackageSource="$(mktemp -d)" | |
echo "TempPackageSource=$TempPackageSource" | tee $GITHUB_ENV | |
dotnet nuget add source "$TempPackageSource" --name 'TempPackageSource' | |
dotnet nuget enable source 'TempPackageSource' | |
- name: Publish to local Package Source (such that `dotnet build` can resolve latest package versions) | |
if: steps.version-check.outputs.changed == 'true' | |
run: | | |
dotnet build \ | |
--configuration Release \ | |
--output "$TempPackageSource" \ | |
JBSnorro/JBSnorro.csproj | |
- name: Build | |
if: steps.version-check.outputs.changed == 'true' | |
run: dotnet build --configuration Release | |
- name: Wait for CI | |
if: steps.version-check.outputs.changed == 'true' | |
uses: deepinsight-io/action-wait-on-workflow@v2.1.1 | |
with: | |
workflowName: ${{ matrix.workflowName }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish | |
if: steps.version-check.outputs.changed == 'true' && github.ref == 'refs/heads/main' | |
run: | | |
dotnet nuget push "./${project}/bin/Release/${project}.${new_version}.symbols.nupkg" \ | |
--api-key '${{ secrets.NUGET_API_KEY }}' \ | |
--source 'https://api.nuget.org/v3/index.json' | |
env: | |
project: ${{ matrix.project }} | |
new_version: ${{ steps.version-check.outputs.new-version }} |