Publish to NuGet #51
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 to NuGet | |
on: | |
push: | |
branches: | |
- main # Trigger on push to the main branch | |
workflow_dispatch: # Allow manual kick off | |
schedule: | |
- cron: '0 0 * * 0' # Runs at midnight every Sunday (UTC time) | |
jobs: | |
publish: | |
runs-on: ubuntu-latest # Use a Linux runner | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup .NET 6 | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: '6.0.x' # Use .NET 6 | |
- name: Compare release versions | |
id: get-releases | |
run: | | |
simple_icons_version="$(curl --retry 5 -s https://api.github.com/repos/simple-icons/simple-icons/releases/latest | jq -r .tag_name)" | |
echo "si=$simple_icons_version" >> $GITHUB_OUTPUT | |
lib_version=$(grep '<Version>' source/timewarp-simple-icons/timewarp-simple-icons.csproj | sed 's/[^0-9.]*\([0-9.]*\).*/\1/') | |
echo "lib=$lib_version" >> $GITHUB_OUTPUT | |
echo "Fetching latest simple-icons version..." | |
echo "Latest simple-icons version: $simple_icons_version" | |
echo "Fetching version from csproj..." | |
echo "Version from csproj: $lib_version" | |
- name: Update Csproj | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
run: | | |
echo "Fetching latest simple-icons version: $steps.get-releases.outputs.si" | |
echo "Fetching old simple-icons version: $steps.get-releases.outputs.lib" | |
sed -i "s/<Version>[^<]*<\/Version>/<Version>${{ steps.get-releases.outputs.si }}<\/Version>/" source/timewarp-simple-icons/timewarp-simple-icons.csproj | |
- name: Update release.md | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
run: | | |
latest_version="${{ steps.get-releases.outputs.si }}" | |
release_notes="Update to simple-icons version $latest_version" | |
sed -i "1s/^# Releases$/# Releases\n\n## $latest_version\n\n* $release_notes\n/" releases.md | |
- name: Checkout simple icons repository | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
uses: actions/checkout@v2 | |
with: | |
repository: simple-icons/simple-icons | |
path: my-tools | |
- name: List clone files | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
run: | | |
cd $GITHUB_WORKSPACE/my-tools # Change directory to the cloned repository | |
ls # List the contents of the cloned repository directory | |
- name: Run PowerShell script to update icons | |
shell: pwsh | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
run: | | |
Push-Location tools\transform | |
try { | |
dotnet run --project transform.csproj -- "${{ github.workspace }}/my-tools/icons" "${{ github.workspace }}/source/timewarp-simple-icons/icons" | |
} | |
finally { | |
Pop-Location | |
} | |
- name: Delete cloned repository | |
run: | | |
rm -rf $GITHUB_WORKSPACE/my-tools | |
- name: Commit and push changes | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
env: | |
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} | |
run: | | |
echo "Git Token: ${{ secrets.REPO_ACCESS_TOKEN }}" | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions Bot" | |
git add . | |
git commit -m "Update to simple-icons version ${{ steps.get-releases.outputs.si }}" | |
git push https://github.com/${{ github.repository }}.git HEAD:main | |
- name: Set NuGet Key | |
run: echo "Nuget_Key=${{ secrets.PUBLISH_TO_NUGET_ORG }}" >> $GITHUB_ENV | |
- name: Set NuGet Key and Publish to NuGet | |
if: steps.get-releases.outputs.lib != steps.get-releases.outputs.si | |
run: | | |
$Nuget_Key = "${{ secrets.PUBLISH_TO_NUGET_ORG }}" | |
./publish.ps1 | |
shell: pwsh # Use PowerShell Core |