Skip to content

Commit 51e9cf4

Browse files
committed
migrate GitHub build step scripts to PowerShell
1 parent b7ddb40 commit 51e9cf4

File tree

2 files changed

+73
-63
lines changed

2 files changed

+73
-63
lines changed

.github/workflows/build-smapi.yml

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,83 +13,91 @@ jobs:
1313
permissions:
1414
contents: write # For creating releases.
1515
id-token: write # For creating attestations.
16-
attestations: write
16+
attestations: write
1717
steps:
1818
- name: Checkout code
1919
uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
2222

23-
- name: Get trigger type.
23+
- name: Get trigger type.
2424
id: trigger-type # Possible values: tag, dev-branch.
25+
shell: pwsh
2526
run: |
2627
# If we ever decide to add manual workflow runs, this will need to be reworked.
2728
28-
if [[ "${{ github.ref_type }}" == "tag" ]]; then
29-
echo "Building regular release."
30-
echo "trigger_type=tag" >> $GITHUB_OUTPUT
31-
elif [[ "${{ github.ref_name }}" == "develop" ]]; then
32-
echo "Building in-development release."
33-
echo "trigger_type=dev-branch" >> $GITHUB_OUTPUT
34-
else
35-
echo "Ran into an unexpected trigger type. Aborting."
36-
echo "Debug info:"
37-
echo "ref_type: ${{ github.ref_type }}"
38-
echo "ref_name: ${{ github.ref_name }}"
39-
29+
if ('${{github.ref_type}}' -eq 'tag') {
30+
Write-Host 'Building regular release.'
31+
'trigger_type=tag' | Out-File -FilePath $env:GITHUB_OUTPUT -Append
32+
}
33+
elseif ('${{github.ref_name}}' -eq 'develop') {
34+
Write-Host 'Building in-development release.'
35+
'trigger_type=dev-branch' | Out-File -FilePath $env:GITHUB_OUTPUT -Append
36+
}
37+
else {
38+
Write-Error 'Ran into an unexpected trigger type. Aborting.'
39+
Write-Host 'Debug info:'
40+
Write-Host 'ref_type: ${{github.ref_type}}'
41+
Write-Host 'ref_name: ${{github.ref_name}}'
4042
exit 1
41-
fi
43+
}
4244
4345
- name: Extract current SMAPI version.
4446
id: smapi-version
47+
shell: pwsh
4548
run: |
46-
version=$(pwsh -Command "([xml](Get-Content build/common.targets)).Project.PropertyGroup.Version")
47-
pattern="^([0-9]+)\.([0-9]+)\.([0-9]+)$"
48-
49-
if [[ "$version" =~ $pattern ]]; then
50-
MAJOR="${BASH_REMATCH[1]}"
51-
MINOR="${BASH_REMATCH[2]}"
52-
PATCH="${BASH_REMATCH[3]}"
53-
else
54-
echo "Input semver did not match the strict x.y.z format. Aborting."
55-
echo "Debug info:"
56-
echo "Extracted version: $version"
57-
49+
[xml]$xml = Get-Content build/common.targets
50+
[string]$version = $xml.Project.PropertyGroup.Version
51+
$version = $version.Trim()
52+
53+
$pattern = '^(\d+)\.(\d+)\.(\d+)$'
54+
if ($version -match $pattern) {
55+
$major = $Matches[1]
56+
$minor = $Matches[2]
57+
$patch = $Matches[3]
58+
}
59+
else {
60+
Write-Error 'Input semver did not match the strict x.y.z format. Aborting.'
61+
Write-Host 'Debug info:'
62+
Write-Host "Extracted version: $version"
5863
exit 1
59-
fi
64+
}
65+
66+
"smapi_version=$version" | Out-File $env:GITHUB_OUTPUT -Append
67+
"smapi_major=$major" | Out-File $env:GITHUB_OUTPUT -Append
68+
"smapi_minor=$minor" | Out-File $env:GITHUB_OUTPUT -Append
69+
"smapi_patch=$patch" | Out-File $env:GITHUB_OUTPUT -Append
70+
"VERSION=$major.$minor.$patch" | Out-File $env:GITHUB_ENV -Append
6071
61-
echo "smapi_version=$version" >> $GITHUB_OUTPUT
62-
echo "smapi_major=$MAJOR" >> $GITHUB_OUTPUT
63-
echo "smapi_minor=$MINOR" >> $GITHUB_OUTPUT
64-
echo "smapi_patch=$PATCH" >> $GITHUB_OUTPUT
65-
echo "VERSION=$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV
66-
echo "Version: $MAJOR.$MINOR.$PATCH"
72+
Write-Host "Version: $major.$minor.$patch"
6773
6874
- name: Verify SMAPI version matches tag.
6975
if: steps.trigger-type.outputs.trigger_type == 'tag'
76+
shell: pwsh
7077
run: |
71-
if [[ "$VERSION" != "${{ github.ref_name }}" ]]; then
72-
echo "The pushed tag doesn't match the version we have in build/common.targets. Aborting."
73-
echo "Debug info: "
74-
echo "Tag: ${{ github.ref_name }}"
75-
echo "In common.targets: $VERSION"
76-
78+
if ($env:VERSION -ne '${{github.ref_name}}') {
79+
Write-Error 'The pushed tag doesn't match the version we have in build/common.targets. Aborting.'
80+
Write-Host 'Debug info:'
81+
Write-Host 'Tag: ${{github.ref_name}}'
82+
Write-Host "In common.targets: $env:VERSION"
7783
exit 1
78-
fi
84+
}
7985
8086
- name: Update SMAPI's current version for dev builds.
81-
id: version-parsing
87+
id: version-parsing
8288
if: steps.trigger-type.outputs.trigger_type == 'dev-branch'
89+
shell: pwsh
8390
run: |
84-
updated_patch=$((${{steps.smapi-version.outputs.smapi_patch}} + 1))
85-
date=$(date +"%Y%m%d")
86-
updated_version=${{steps.smapi-version.outputs.smapi_major}}.${{steps.smapi-version.outputs.smapi_minor}}.$updated_patch-alpha.$date
87-
echo "VERSION=$updated_version" >> $GITHUB_ENV
91+
$updatedPatch = [int]${{steps.smapi-version.outputs.smapi_patch}} + 1
92+
$date = Get-Date -Format 'yyyyMMdd'
93+
$updatedVersion = "${{steps.smapi-version.outputs.smapi_major}}.${{steps.smapi-version.outputs.smapi_minor}}.$updatedPatch-alpha.$date"
94+
95+
"VERSION=$updatedVersion" | Out-File $env:GITHUB_ENV -Append
8896
89-
echo "This is a dev version. Building as version: $updated_version"
97+
Write-Host "This is a dev version. Building as version: $updatedVersion"
9098
91-
build/unix/set-smapi-version.sh "$updated_version"
92-
echo "Version updated using build/unix/set-smapi-version.sh."
99+
bash build/unix/set-smapi-version.sh "$updatedVersion"
100+
Write-Host 'Version updated using build/unix/set-smapi-version.sh.'
93101
94102
- name: Checkout reference assemblies
95103
uses: actions/checkout@v4
@@ -103,37 +111,38 @@ jobs:
103111
ln -s "$(pwd)/stardew-reference-assemblies" "$HOME/StardewValley"
104112
105113
- name: Build SMAPI.
114+
shell: pwsh
106115
run: |
107-
echo "Building SMAPI $VERSION."
108-
build/unix/prepare-install-package.sh "$VERSION"
116+
Write-Host "Building SMAPI $env:VERSION."
117+
bash build/unix/prepare-install-package.sh "$env:VERSION"
109118
110119
- name: Rename build zips.
111120
run: |
112-
mv "bin/SMAPI ${{ env.VERSION }} installer.zip" "bin/SMAPI-${{ env.VERSION }}-installer.zip"
113-
mv "bin/SMAPI ${{ env.VERSION }} installer for developers.zip" "bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip"
121+
mv "bin/SMAPI ${{env.VERSION}} installer.zip" "bin/SMAPI-${{env.VERSION}}-installer.zip"
122+
mv "bin/SMAPI ${{env.VERSION}} installer for developers.zip" "bin/SMAPI-${{env.VERSION}}-installer-for-developers.zip"
114123
115124
- name: Upload regular installer.
116125
uses: actions/upload-artifact@v4
117126
with:
118-
name: 'SMAPI ${{ env.VERSION }} installer'
119-
path: 'bin/SMAPI-${{ env.VERSION }}-installer.zip'
127+
name: 'SMAPI ${{env.VERSION}} installer'
128+
path: 'bin/SMAPI-${{env.VERSION}}-installer.zip'
120129
if-no-files-found: 'error'
121130

122131
- name: Upload installer for developers.
123132
uses: actions/upload-artifact@v4
124133
with:
125-
name: "SMAPI ${{ env.VERSION }} installer for developers"
126-
path: "bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip"
134+
name: 'SMAPI ${{env.VERSION}} installer for developers'
135+
path: 'bin/SMAPI-${{env.VERSION}}-installer-for-developers.zip'
127136
if-no-files-found: 'error'
128137

129138
- name: Create release and upload artifact
130139
uses: ncipollo/release-action@v1
131140
if: steps.trigger-type.outputs.trigger_type == 'tag'
132141
with:
133-
artifacts: "bin/SMAPI-${{ env.VERSION }}*.zip"
134-
token: ${{ secrets.GITHUB_TOKEN }}
135-
tag: ${{ github.ref_name }}
136-
name: "${{ env.VERSION }}"
142+
artifacts: 'bin/SMAPI-${{env.VERSION}}*.zip'
143+
token: '${{secrets.GITHUB_TOKEN}}'
144+
tag: '${{github.ref_name}}'
145+
name: "${{env.VERSION}}"
137146
body: |
138147
Draft.
139148
draft: true
@@ -143,5 +152,5 @@ jobs:
143152
id: attestation-step
144153
with:
145154
subject-path: |
146-
bin/SMAPI-${{ env.VERSION }}-installer.zip
147-
bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip
155+
bin/SMAPI-${{env.VERSION}}-installer.zip
156+
bin/SMAPI-${{env.VERSION}}-installer-for-developers.zip

src/SMAPI.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<Folder Name="/.root/.github/">
1010
<File Path="../.github/CONTRIBUTING.md" />
1111
<File Path="../.github/SUPPORT.md" />
12+
<File Path="../.github/workflows/build-smapi.yml" />
1213
</Folder>
1314
<Folder Name="/.root/.github/ISSUE_TEMPLATE/">
1415
<File Path="../.github/ISSUE_TEMPLATE/config.yml" />

0 commit comments

Comments
 (0)