Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions .github/workflows/build-smapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Build SMAPI

on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+" # On any d.d.d tag push.
branches:
- develop

jobs:
build_and_release:
runs-on: ubuntu-latest
permissions:
contents: write # For creating releases.
id-token: write # For creating attestations.
attestations: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get trigger type.
id: trigger-type # Possible values: tag, dev-branch.
run: |
# If we ever decide to add manual workflow runs, this will need to be reworked.

if [[ "${{ github.ref_type }}" == "tag" ]]; then
echo "Building regular release."
echo "trigger_type=tag" >> $GITHUB_OUTPUT
elif [[ "${{ github.ref_name }}" == "develop" ]]; then
echo "Building in-development release."
echo "trigger_type=dev-branch" >> $GITHUB_OUTPUT
else
echo "Ran into an unexpected trigger type. Aborting."
echo "Debug info:"
echo "ref_type: ${{ github.ref_type }}"
echo "ref_name: ${{ github.ref_name }}"

exit 1
fi

- name: Extract current SMAPI version.
id: smapi-version
run: |
version=$(pwsh -Command "([xml](Get-Content build/common.targets)).Project.PropertyGroup.Version")
pattern="^([0-9]+)\.([0-9]+)\.([0-9]+)$"

if [[ "$version" =~ $pattern ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
else
echo "Input semver did not match the strict x.y.z format. Aborting."
echo "Debug info:"
echo "Extracted version: $version"

exit 1
fi

echo "smapi_version=$version" >> $GITHUB_OUTPUT
echo "smapi_major=$MAJOR" >> $GITHUB_OUTPUT
echo "smapi_minor=$MINOR" >> $GITHUB_OUTPUT
echo "smapi_patch=$PATCH" >> $GITHUB_OUTPUT
echo "VERSION=$MAJOR.$MINOR.$PATCH" >> $GITHUB_ENV
echo "Version: $MAJOR.$MINOR.$PATCH"

- name: Verify SMAPI version matches tag.
if: steps.trigger-type.outputs.trigger_type == 'tag'
run: |
if [[ "$VERSION" != "${{ github.ref_name }}" ]]; then
echo "The pushed tag doesn't match the version we have in build/common.targets. Aborting."
echo "Debug info: "
echo "Tag: ${{ github.ref_name }}"
echo "In common.targets: $VERSION"

exit 1
fi

- name: Update SMAPI's current version for dev builds.
id: version-parsing
if: steps.trigger-type.outputs.trigger_type == 'dev-branch'
run: |
updated_patch=$((${{steps.smapi-version.outputs.smapi_patch}} + 1))
date=$(date +"%Y%m%d")
updated_version=${{steps.smapi-version.outputs.smapi_major}}.${{steps.smapi-version.outputs.smapi_minor}}.$updated_patch-alpha.$date
echo "VERSION=$updated_version" >> $GITHUB_ENV

echo "This is a dev version. Building as version: $updated_version"

build/unix/set-smapi-version.sh "$updated_version"
echo "Version updated using build/unix/set-smapi-version.sh."

- name: Checkout reference assemblies
uses: actions/checkout@v4
with:
repository: "StardewModders/mod-reference-assemblies"
path: "stardew-reference-assemblies"
fetch-depth: 1

- name: Symlink reference assemblies to a valid location. # Simply cloning the repo to this location doesn't seem to work.
run: |
ln -s "$(pwd)/stardew-reference-assemblies" "$HOME/StardewValley"

- name: Build SMAPI.
run: |
echo "Building SMAPI $VERSION."
build/unix/prepare-install-package.sh "$VERSION"

- name: Rename build zips.
run: |
mv "bin/SMAPI ${{ env.VERSION }} installer.zip" "bin/SMAPI-${{ env.VERSION }}-installer.zip"
mv "bin/SMAPI ${{ env.VERSION }} installer for developers.zip" "bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip"

- name: Upload regular installer.
uses: actions/upload-artifact@v4
with:
name: 'SMAPI ${{ env.VERSION }} installer'
path: 'bin/SMAPI-${{ env.VERSION }}-installer.zip'
if-no-files-found: 'error'

- name: Upload installer for developers.
uses: actions/upload-artifact@v4
with:
name: "SMAPI ${{ env.VERSION }} installer for developers"
path: "bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip"
if-no-files-found: 'error'

- name: Create release and upload artifact
uses: ncipollo/release-action@v1
if: steps.trigger-type.outputs.trigger_type == 'tag'
with:
artifacts: "bin/SMAPI-${{ env.VERSION }}*.zip"
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
name: "${{ env.VERSION }}"
body: |
Draft.
draft: true

- name: Generate artifact attestations
uses: actions/attest-build-provenance@v2
id: attestation-step
with:
subject-path: |
bin/SMAPI-${{ env.VERSION }}-installer.zip
bin/SMAPI-${{ env.VERSION }}-installer-for-developers.zip