Workflow file for this run
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 NuGet and upload release | |
env: | |
MOD_ID: 3482 | |
KSP2_ID: 22407 | |
on: | |
release: | |
types: [ "published" ] | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
- name: Install jq | |
uses: dcarbone/[email protected] | |
- name: Download NuGet | |
id: download-nuget | |
run: | | |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe | |
- name: Build the solution | |
run: dotnet build "PatchManager.sln" -c Release | |
- name: Extract current version | |
id: get-version | |
run: | | |
version=$(jq -r '.version' plugin_template/swinfo.json) | |
echo "Version is $version" | |
echo "version=$version" >> $GITHUB_ENV | |
echo "artifact_name=PatchManager-$version.zip" >> $GITHUB_ENV | |
echo "zip=$(ls -1 dist/PatchManager-*.zip | head -n 1)" >> $GITHUB_ENV | |
echo "upload_url=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].upload_url' | tr -d \")" >> $GITHUB_ENV | |
echo "changelog=$(wget -qO- https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq '.[0].body' | tr -d \" | jq -Rr @uri)" >> $GITHUB_ENV | |
- name: Check if version exists | |
id: check-version | |
run: | | |
version=${{ env.version }} | |
response=$(curl -s "https://nuget.spacewarp.org/v3/search?q=PatchManager") | |
exists=$(echo "$response" | jq -r --arg id "PatchManager" --arg version "$version" '.data[] | select(.id == $id) | .versions[] | select(.version == $version) | .version') | |
if [ "$exists" == "$version" ]; then | |
echo "Version $version already exists in the NuGet repository" | |
else | |
echo "Version $version does not exist in the NuGet repository" | |
echo "should_publish=true" >> $GITHUB_ENV | |
fi | |
- name: Publish NuGet package | |
if: env.should_publish == 'true' | |
run: | | |
nupkg_path=$(ls -1 nuget/PatchManager.*.nupkg | head -n 1) | |
dotnet nuget push "$nupkg_path" -s https://nuget.spacewarp.org/v3/index.json -k ${{ secrets.NUGET_SERVER_KEY }} | |
- name: Upload Zip | |
uses: shogo82148/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ env.upload_url }} | |
asset_path: ${{ env.zip }} | |
asset_name: ${{ env.artifact_name }} | |
asset_content_type: application/zip | |
- name: Add Mask | |
run: echo "::add-mask::${{ secrets.SPACEDOCK_PASSWORD }}" | |
- name: Log in to spacedock | |
run: | | |
login_response=$(curl -F username=${{ secrets.SPACEDOCK_USER }} -F password=${{ secrets.SPACEDOCK_PASSWORD }} -c ./cookies "https://spacedock.info/api/login") | |
login_errored=$(echo $login_response | jq .error) | |
if [ "$login_errored" == "true" ]; then | |
echo "Login to space dock errored: $(echo $login_response | jq .reason)" | |
exit 1 | |
else | |
echo "Login to space dock successful" | |
fi | |
- name: Query latest game version | |
run: | | |
echo "LATEST_GAME_VERSION=$(curl 'https://spacedock.info/api/${{ env.KSP2_ID }}/versions' | jq '.[0].friendly_version' | tr -d \")" >> $GITHUB_ENV | |
- name: Update mod on spacedock | |
run: | | |
result=$(curl -b ./cookies -F "version=${{ env.version }}" -F "changelog=${{ env.changelog }}" -F "game-version=${{ env.LATEST_GAME_VERSION }}" -F "notify-followers=yes" -F "zipball=@${{ env.zip }}" "https://spacedock.info/api/mod/${{ env.MOD_ID }}/update") | |
errored=$(echo $result | jq .error) | |
if [ "$errored" == "true" ]; then | |
echo "Upload to space dock errored: $(echo $result | jq .reason)" | |
exit 1 | |
else | |
echo "Upload to space dock successful" | |
fi | |