GitHub. Extract variables #16
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: Xcode - Build and Test | |
on: [push] | |
jobs: | |
build: | |
name: Build and test | |
runs-on: macos-14 | |
steps: | |
- name: Extract variables | |
env: | |
JSON: ${{ toJSON(github) }} | |
run: | | |
echo $JSON | |
false | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Select Xcode version | |
run: | | |
ls /Applications | |
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer | |
xcode-select -p | |
- name: Install the Apple certificate | |
env: | |
BUILD_CERTIFICATE_BASE64: ${{ secrets.CERTIFICATE_P12 }} | |
P12_PASSWORD: ${{ secrets.PASSWORD_P12 }} | |
KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
run: | | |
# create variables | |
CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 | |
KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | |
# import certificate and provisioning profile from secrets | |
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 -d -o $CERTIFICATE_PATH | |
# create temporary keychain | |
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH | |
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
# import certificate to keychain | |
security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH | |
security list-keychain -d user -s $KEYCHAIN_PATH | |
- name: Build and analyze | |
run: | |
xcodebuild build analyze | |
-scheme ${{ github.event.repository.name }} | |
-destination platform=macOS | |
-showBuildTimingSummary | | |
xcpretty && exit ${PIPESTATUS[0]} | |
- name: Archive | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | |
xcodebuild archive | |
-project "${{ github.event.repository.name }}.xcodeproj" | |
-scheme ${{ github.event.repository.name }} | |
-archivePath "dist/${{ github.event.repository.name }}.xcarchive" | |
- name: Export options | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
echo ' | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>method</key> | |
<string>mac-application</string> | |
</dict> | |
</plist> | |
' > ExportOptions.plist | |
- name: Export | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | |
xcodebuild -exportArchive | |
-archivePath "dist/${{ github.event.repository.name }}.xcarchive" | |
-exportOptionsPlist ExportOptions.plist | |
-exportPath dist/ | |
-allowProvisioningUpdates | |
- name: Create Disk Image | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
brew install create-dmg | |
rm -r "dist/${{ github.event.repository.name }}.xcarchive" | |
ln -s /Applications dist/ | |
create-dmg "${{ github.event.repository.name }}.dmg" dist | |
- name: Upload artifact | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "${{ github.event.repository.name }}.dmg" | |
path: "${{ github.event.repository.name }}.dmg" | |
if-no-files-found: error | |
retention-days: 0 | |
compression-level: 0 | |
overwrite: true |