Skip to content

Commit

Permalink
ci: use local custom actions for OS-specific steps
Browse files Browse the repository at this point in the history
  • Loading branch information
cwillisf committed Aug 23, 2023
1 parent 9ab7173 commit a503458
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 64 deletions.
48 changes: 48 additions & 0 deletions .github/actions/macos-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build for macOS
description: Core build steps for macOS
inputs:
configuration:
description: The configuration to build, like "Debug"
required: true
default: Debug
artifact_tag:
description: A string to tag the build artifact, like "Debug" or "MAS"
required: false
default: ""
ac_username:
description: App Store Connect user name
required: true
default: ""
ac_password:
description: App Store Connect password
required: true
default: "secret"
runs:
using: composite
steps:
- name: Build Safari helper
env:
AC_USERNAME: ${{ inputs.ac_username }}
AC_PASSWORD: ${{ inputs.ac_password }}
shell: bash
run: xcodebuild -project "Scratch Link Safari Helper/Scratch Link Safari Helper.xcodeproj" -scheme "Scratch Link Safari Helper" clean build
- name: "Build for Mac: ${{ inputs.configuration }}"
env:
CONFIG: Debug
ARTIFACT_TAG: Debug
shell: bash
run: |
msbuild -m -t:Restore -p:Configuration=${{ inputs.configuration }}_Mac scratch-link.sln
"/Applications/Visual Studio.app/Contents/MacOS/vstool" build -t:Build -c:${{ inputs.configuration }}_Mac "${PWD}/scratch-link.sln"
# "for" is just a convenient way to resolve the glob to a variable so we can DRY the filename for "if" and "mv"
for PKGPATH in scratch-link-mac/bin/${{ inputs.configuration }}/"Scratch Link"*.pkg; do
if [ -r "$PKGPATH" ]; then
PKGFILE="${PKGPATH##*/}"
if [ -n "${{ inputs.artifact_tag }}" ]; then
PKGFILE="${PKGFILE/Scratch Link/Scratch Link-${{ inputs.artifact_tag }}"
fi
mkdir -p Artifacts
fi
# this is outside the "if" to force an error if the file doesn't exist
mv -v "$PKGPATH" "Artifacts/${PKGFILE}"
done
51 changes: 51 additions & 0 deletions .github/actions/windows-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build for Windows
description: Core build steps for Windows
inputs:
configuration:
description: The configuration to build, like "Debug"
required: true
default: Debug
artifact_tag:
description: A string to tag the build artifact, like "Debug" or "MAS"
required: false
default: ""
runs:
using: composite
steps:
- name: Add msbuild to PATH
uses: microsoft/[email protected]
- env:
CONFIG: Debug
ARTIFACT_TAG: Debug
name: "Build for Windows: ${{ inputs.configuration }}"
shell: pwsh
run: |
# Build the MSIX project instead of the Solution because msbuild gets grumpy about the Mac project.
# That means SolutionDir needs to be set artificially, though.
# The `UapAppxPackageBuildMode=StoreAndSideload` means it'll build both MSIXUpload and MSIXBundle.
# The StoreUpload mode does that too, but that might be a bug, and semantically "StoreAndSideload" is what we want.
msbuild scratch-link-win-msix/scratch-link-win-msix.wapproj -maxCpuCount -restore -t:Build -p:SolutionDir="$PWD\" -p:Configuration="${{ inputs.configuration }}_Win" -p:AppxBundlePlatforms="x86|x64|ARM64" -p:AppxBundle=Always -p:UapAppxPackageBuildMode=StoreAndSideload
- env:
CONFIG: Debug
ARTIFACT_TAG: Debug
name: "Move Windows artifacts into place: ${{ inputs.configuration }}"
shell: bash
run: |
mkdir -p Artifacts
# The store package is fine as is: no user will see this filename.
mv -v scratch-link-win-msix/AppPackages/scratch-link-win-msix_*_${{ inputs.configuration }}_Win.msixupload Artifacts/
# Transform the bundle for a more user-friendly filename
for PKGPATH in scratch-link-win-msix/AppPackages/scratch-link-win-msix_*_${{ inputs.configuration }}_Win_Test/scratch-link-win-msix_*_${{ inputs.configuration }}_Win.msixbundle; do
if [ -r "$PKGPATH" ]; then
PKGFILE="${PKGPATH##*/}"
[[ $PKGFILE =~ scratch-link-win-msix_([.0-9]+)_(.*)_${{ inputs.configuration }}_Win.msixbundle$ ]]
PKGVERSION=${BASH_REMATCH[1]}
PKGPLATFORMS=${BASH_REMATCH[2]}
fi
# do the move outside the "if" above to force an error if the file doesn't exist
if [ -z "${{ inputs.artifact_tag }}" ]; then
mv -v "$PKGPATH" "Artifacts/Scratch Link ${PKGVERSION}.msixbundle"
else
mv -v "$PKGPATH" "Artifacts/Scratch Link ${PKGVERSION} ${{ inputs.artifact_tag }}.msixbundle"
fi
done
66 changes: 2 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,72 +68,10 @@ jobs:
git pull --tags semantic-release ${{ github.ref_name }}
git fetch semantic-release 'refs/notes/*:refs/notes/*' # semantic-release tracks channels with notes
- name: Build Safari helper
- uses: ./.github/actions/macos-build
if: runner.os == 'macOS'
env:
AC_USERNAME: ${{ secrets.AC_USERNAME }}
AC_PASSWORD: ${{ secrets.AC_USERNAME }}
run: xcodebuild -project "Scratch Link Safari Helper/Scratch Link Safari Helper.xcodeproj" -scheme "Scratch Link Safari Helper" clean build
- env:
CONFIG: Debug
ARTIFACT_TAG: Debug
name: "Build for Mac: ${{ env.CONFIG }}"
if: runner.os == 'macOS'
run: |
msbuild -m -t:Restore -p:Configuration=${CONFIG}_Mac scratch-link.sln
"/Applications/Visual Studio.app/Contents/MacOS/vstool" build -t:Build -c:${CONFIG}_Mac "${PWD}/scratch-link.sln"
# "for" is just a convenient way to resolve the glob to a variable so we can DRY the filename for "if" and "mv"
for PKGPATH in scratch-link-mac/bin/${CONFIG}/"Scratch Link"*.pkg; do
if [ -r "$PKGPATH" ]; then
PKGFILE="${PKGPATH##*/}"
if [ -n "${ARTIFACT_TAG}" ]; then
PKGFILE="${PKGFILE/Scratch Link/Scratch Link-${ARTIFACT_TAG}}"
fi
mkdir -p Artifacts
fi
# this is outside the "if" to force an error if the file doesn't exist
mv -v "$PKGPATH" "Artifacts/${PKGFILE}"
done
- name: Add msbuild to PATH
if: runner.os == 'Windows'
uses: microsoft/[email protected]
- env:
CONFIG: Debug
ARTIFACT_TAG: Debug
name: "Build for Windows: ${{ env.CONFIG }}"
- uses: ./.github/actions/windows-build
if: runner.os == 'Windows'
run: |
# Build the MSIX project instead of the Solution because msbuild gets grumpy about the Mac project.
# That means SolutionDir needs to be set artificially, though.
# The `UapAppxPackageBuildMode=StoreAndSideload` means it'll build both MSIXUpload and MSIXBundle.
# The StoreUpload mode does that too, but that might be a bug, and semantically "StoreAndSideload" is what we want.
msbuild scratch-link-win-msix/scratch-link-win-msix.wapproj -maxCpuCount -restore -t:Build -p:SolutionDir="$PWD\" -p:Configuration="${env:CONFIG}_Win" -p:AppxBundlePlatforms="x86|x64|ARM64" -p:AppxBundle=Always -p:UapAppxPackageBuildMode=StoreAndSideload
- env:
CONFIG: Debug
ARTIFACT_TAG: Debug
name: "Move Windows artifacts into place: ${{ env.CONFIG }}"
if: runner.os == 'Windows'
shell: bash
run: |
mkdir -p Artifacts
# The store package is fine as is: no user will see this filename.
mv -v scratch-link-win-msix/AppPackages/scratch-link-win-msix_*_${CONFIG}_Win.msixupload Artifacts/
# Transform the bundle for a more user-friendly filename
for PKGPATH in scratch-link-win-msix/AppPackages/scratch-link-win-msix_*_${CONFIG}_Win_Test/scratch-link-win-msix_*_${CONFIG}_Win.msixbundle; do
if [ -r "$PKGPATH" ]; then
PKGFILE="${PKGPATH##*/}"
[[ $PKGFILE =~ scratch-link-win-msix_([.0-9]+)_(.*)_${CONFIG}_Win.msixbundle$ ]]
PKGVERSION=${BASH_REMATCH[1]}
PKGPLATFORMS=${BASH_REMATCH[2]}
fi
# do the move outside the "if" above to force an error if the file doesn't exist
if [ -z "${ARTIFACT_TAG}" ]; then
mv -v "$PKGPATH" "Artifacts/Scratch Link ${PKGVERSION}.msixbundle"
else
mv -v "$PKGPATH" "Artifacts/Scratch Link ${PKGVERSION} ${ARTIFACT_TAG}.msixbundle"
fi
done

- uses: actions/upload-artifact@v3
with:
Expand Down
15 changes: 15 additions & 0 deletions scratch-link.sln
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\ci.yml = .github\workflows\ci.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "actions", "actions", "{4B4A2E1C-2249-4246-A149-F6CB8BF73666}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "macos-build", "macos-build", "{D4F02497-7C96-4987-8F9C-7293FE3A4B1C}"
ProjectSection(SolutionItems) = preProject
.github\actions\macos-build\action.yml = .github\actions\macos-build\action.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "windows-build", "windows-build", "{EB90F542-2DCD-4832-9827-818A7C8980E9}"
ProjectSection(SolutionItems) = preProject
.github\actions\windows-build\action.yml = .github\actions\windows-build\action.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Mac|Any CPU = Debug_Mac|Any CPU
Expand Down Expand Up @@ -207,6 +219,9 @@ Global
{172A147D-A614-4442-B600-BAC18EF8F1DF} = {E37C17DD-8722-46CA-AB2F-B2A42845B3B1}
{05F0C24B-4EA1-4B11-9F86-DB3F1EDEE785} = {E37C17DD-8722-46CA-AB2F-B2A42845B3B1}
{D5766652-E655-4726-8289-C45C43A14639} = {05F0C24B-4EA1-4B11-9F86-DB3F1EDEE785}
{4B4A2E1C-2249-4246-A149-F6CB8BF73666} = {05F0C24B-4EA1-4B11-9F86-DB3F1EDEE785}
{D4F02497-7C96-4987-8F9C-7293FE3A4B1C} = {4B4A2E1C-2249-4246-A149-F6CB8BF73666}
{EB90F542-2DCD-4832-9827-818A7C8980E9} = {4B4A2E1C-2249-4246-A149-F6CB8BF73666}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
Expand Down

0 comments on commit a503458

Please sign in to comment.