Expand upload action into shell commands #12
Workflow file for this run
This file contains hidden or 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: Release macOS .dmg | |
| on: | |
| push: | |
| tags: 'test*' | |
| jobs: | |
| generate: | |
| name: Create macOS release-artifacts | |
| runs-on: macOS-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Xcode | |
| uses: maxim-lobanov/setup-xcode@v1 | |
| with: | |
| xcode-version: latest-stable | |
| - name: Set up Apple certificate | |
| env: | |
| BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} | |
| P12_PASSWORD: ${{ secrets.P12_PASSWORD }} | |
| KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} | |
| run: | | |
| CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 | |
| KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db | |
| echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -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 set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH | |
| security list-keychain -d user -s $KEYCHAIN_PATH | |
| - name: Install node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - name: Build create-dmg | |
| run: npm install --global create-dmg | |
| - name: Build app for macOS | |
| run: | | |
| xcodebuild \ | |
| -workspace BTrain.xcodeproj/project.xcworkspace \ | |
| -scheme BTrain \ | |
| -configuration Release \ | |
| -archivePath ./build/BTrain.xcarchive archive | |
| xcodebuild \ | |
| -exportArchive -archivePath ./build/BTrain.xcarchive \ | |
| -exportOptionsPlist build/BTrain.xcarchive/Info.plist \ | |
| -exportPath ./build/export | |
| - name: Create dmg | |
| run: | | |
| create-dmg ./build/export/BTrain.app \ | |
| --no-version-in-filename \ | |
| ./build/export/ | |
| - name: Upload the artifacts | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" | |
| RELEASE_ID=$"{{ github.ref_name }}" | |
| FILE="./build/export/*.dmg" | |
| FILENAME=$( basename "${FILE}" ) | |
| UPLOAD_URL="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${FILENAME}" | |
| echo "Upload URL is ${UPLOAD_URL}" | |
| # Upload the artifact & capture HTTP response-code in output file. | |
| tmp=$(mktemp) | |
| response=$(curl \ | |
| -sSL \ | |
| -XPOST \ | |
| -H "${AUTH_HEADER}" \ | |
| --upload-file "${FILE}" \ | |
| --header "Content-Type:application/octet-stream" \ | |
| --write-out "%{http_code}" \ | |
| --output $tmp \ | |
| "${UPLOAD_URL}") | |
| if [ "$?" -ne 0 ]; then | |
| echo "**********************************" | |
| echo " curl command did not return zero." | |
| echo " Aborting" | |
| echo "**********************************" | |
| cat $tmp | |
| rm $tmp | |
| exit 1 | |
| fi | |
| # If upload is not successful, we must abort | |
| if [ $response -ge 400 ]; then | |
| echo "***************************" | |
| echo " upload was not successful." | |
| echo " Aborting" | |
| echo " HTTP status is $response" | |
| echo "**********************************" | |
| cat $tmp | |
| rm $tmp | |
| exit 1 | |
| fi | |
| cat $tmp | jq | |
| rm $tmp |