forked from MonkeyModdingTroop/ReferencePackageGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
182 lines (157 loc) · 6.83 KB
/
Copy pathgenerate-references.yml
File metadata and controls
182 lines (157 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: Generate Reference Package
on:
workflow_dispatch:
inputs:
build_version:
description: "Build version from Resonite (optional, uses Build.version if not provided)"
required: false
type: string
branch:
description: "Branch to process"
required: false
default: "public"
type: string
publish:
description: "publish to nuget"
required: false
default: false
type: boolean
schedule:
- cron: "*/10 * * * *"
jobs:
generate:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
steps:
- name: Checkout Repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: "10.0.x"
- name: Download Resonite Assemblies
uses: hazre/resonite-download-action@a0255ea1241b3245c1e6783aa7a3db24d07e11bb # v1.0.2
with:
steam-username: ${{ secrets.STEAM_USERNAME }}
steam-password: ${{ secrets.STEAM_PASSWORD }}
resonite-path: resonite-assemblies
branch: ${{ github.event.inputs.branch || 'public' }}
- name: Resolve Build Metadata
env:
INPUT_BUILD_VERSION: ${{ github.event.inputs.build_version }}
INPUT_BRANCH: ${{ github.event.inputs.branch || 'public' }}
run: |
# Prefer explicit input version for manual runs, otherwise read from Build.version
if [ -n "${INPUT_BUILD_VERSION:-}" ]; then
version="$INPUT_BUILD_VERSION"
echo "Using provided build_version input: $version"
else
version_file="resonite-assemblies/Build.version"
if [ -f "$version_file" ]; then
version=$(cat "$version_file" | tr -d '\r\n')
echo "Read version from Build.version: $version"
else
echo "Error: No build_version provided and Build.version not found"
exit 1
fi
fi
branch="${INPUT_BRANCH:-public}"
echo "Processing branch: $branch"
if [ "$branch" != "public" ]; then
sanitized_branch=$(echo "$branch" | sed 's/[^a-zA-Z0-9-]/-/g')
version="${version}-${sanitized_branch}"
echo "Appended branch name to version for prerelease"
fi
package_name=$(jq -r '.PackageIdPrefix + .SinglePackageName' Resonite.json)
if [ -z "$package_name" ] || [ "$package_name" = "null" ]; then
echo "Error: Could not derive package name from Resonite.json"
exit 1
fi
echo "Using version: $version"
echo "Resolved package name: $package_name"
echo "BUILD_VERSION=$version" >> $GITHUB_ENV
echo "PACKAGE_NAME=$package_name" >> $GITHUB_ENV
- name: Check NuGet for Existing Version
run: |
package_id_lower=$(echo "$PACKAGE_NAME" | tr '[:upper:]' '[:lower:]')
version_lower=$(echo "$BUILD_VERSION" | tr '[:upper:]' '[:lower:]')
index_url="https://api.nuget.org/v3-flatcontainer/${package_id_lower}/index.json"
echo "Checking NuGet for ${PACKAGE_NAME} ${BUILD_VERSION}"
if curl -fsSL "$index_url" | jq -e --arg v "$version_lower" '.versions | map(ascii_downcase) | index($v) != null' > /dev/null; then
echo "Version already exists on NuGet. Marking workflow for early skip."
echo "SKIP_WORKFLOW=true" >> $GITHUB_ENV
else
echo "Version not published yet. Continuing workflow."
echo "SKIP_WORKFLOW=false" >> $GITHUB_ENV
fi
- name: Early Exit (Already Published)
if: env.SKIP_WORKFLOW == 'true'
run: echo "Skipping package generation because this version is already published to NuGet."
- name: Prepare Config
if: env.SKIP_WORKFLOW != 'true'
env:
BUILD_VERSION: ${{ env.BUILD_VERSION }}
run: |
version="$BUILD_VERSION"
# Copy and modify the Resonite.json config
cp Resonite.json resonite-config.json
# Use jq to update paths and version
jq --arg sp "${{ github.workspace }}/resonite-assemblies" \
--arg dp "${{ github.workspace }}/output/dlls" \
--arg np "${{ github.workspace }}/output/packages" \
--arg rp "${{ github.workspace }}/ReferencePackageGenerator/README.md" \
--arg ver "$version" \
'.SourcePath = $sp |
.DllTargetPath = $dp |
.NupkgTargetPath = $np |
.ReadmePath = $rp |
.SinglePackageVersion = $ver' \
resonite-config.json > resonite-config-temp.json
mv resonite-config-temp.json resonite-config.json
echo "Config file prepared from Resonite.json"
- name: Generate Reference Package
if: env.SKIP_WORKFLOW != 'true'
run: |
cd ReferencePackageGenerator
dotnet run -- "${{ github.workspace }}/resonite-config.json"
- name: Attest Build Provenance
if: env.SKIP_WORKFLOW != 'true'
uses: actions/attest-build-provenance@0f67c3f4856b2e3261c31976d6725780e5e4c373 # v4.1.1
with:
subject-path: output/packages/*.nupkg
- name: Upload Package Artifact
if: env.SKIP_WORKFLOW != 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: reference-package-${{ env.BUILD_VERSION }}
path: output/packages/*.nupkg
retention-days: 30
- name: Upload DLLs Artifact
if: env.SKIP_WORKFLOW != 'true'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: stripped-dlls-${{ env.BUILD_VERSION }}
path: output/dlls/*.dll
retention-days: 7
- name: NuGet login (OIDC → temp API key)
if: env.SKIP_WORKFLOW != 'true' && (github.event_name == 'schedule' || github.event.inputs.publish == 'true')
id: login
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0
with:
user: ${{ secrets.NUGET_USER }}
- name: Publish to NuGet
if: env.SKIP_WORKFLOW != 'true' && (github.event_name == 'schedule' || github.event.inputs.publish == 'true')
env:
NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }}
run: |
for package in output/packages/*.nupkg; do
if [ -f "$package" ]; then
echo "Publishing $(basename $package) to NuGet..."
dotnet nuget push "$package" --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json --skip-duplicate
fi
done