Mattk70 is building Chirpity for Intel Mac #577
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: Build Intel Mac version | |
run-name: ${{ github.actor }} is building Chirpity for Intel Mac | |
on: | |
- push | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
Build-Chirpity: | |
runs-on: macos-13 | |
env: | |
GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
CI: true | |
steps: | |
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." | |
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" | |
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." | |
- run: echo "🖥️ The workflow is now ready to test your code on the runner." | |
# Get the latest tag from origin/master | |
- name: Get the latest tag on origin/master | |
id: get_latest_tag | |
shell: bash | |
run: | | |
LATEST_TAG=$(gh api repos/${{ github.repository }}/tags --jq '.[0].name') | |
echo "LATEST_TAG=$LATEST_TAG" | |
echo "LATEST_TAG=$LATEST_TAG" >> $GITHUB_ENV | |
# Get the version from package.json | |
- name: Get the package version | |
id: get_package_version | |
shell: bash | |
run: | | |
PACKAGE_VERSION=$(jq -r .version package.json) | |
echo "PACKAGE_VERSION=$PACKAGE_VERSION" | |
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV | |
# Check if latest tag is a published release | |
- name: Check if latest tag is a published release | |
id: check_published | |
shell: bash | |
run: | | |
echo "Checking if the latest tag ($LATEST_TAG) is a published release..." | |
RELEASE_INFO=$(gh api repos/Mattk70/Chirpity-Electron/releases/tags/$LATEST_TAG 2>/dev/null) || RELEASE_INFO="not_found" | |
if [[ "$RELEASE_INFO" == "not_found" ]]; then | |
echo "No release found for $LATEST_TAG. Assuming it is not published." | |
LATEST_TAG_PUBLISHED=false | |
echo "LATEST_TAG_PUBLISHED=$LATEST_TAG_PUBLISHED" >> $GITHUB_ENV | |
else | |
IS_DRAFT=$(echo "$RELEASE_INFO" | jq -r '.draft') | |
if [[ "$IS_DRAFT" == "true" ]]; then | |
echo "Latest tag ($LATEST_TAG) is a draft." | |
LATEST_TAG_PUBLISHED=false | |
echo "LATEST_TAG_PUBLISHED=false" >> $GITHUB_ENV | |
else | |
echo "Latest tag ($LATEST_TAG) is published." | |
LATEST_TAG_PUBLISHED=true | |
echo "LATEST_TAG_PUBLISHED=true" >> $GITHUB_ENV | |
fi | |
fi | |
echo "LATEST_TAG_PUBLISHED=$LATEST_TAG_PUBLISHED" | |
# Compare package version with latest tag and decide if build should proceed | |
- name: Compare package version with latest tag | |
id: check_tag | |
shell: bash | |
run: | | |
echo "Comparing package.json version ($PACKAGE_VERSION) with latest tag ($LATEST_TAG)..." | |
if [[ "v$PACKAGE_VERSION" == "$LATEST_TAG" && "$LATEST_TAG_PUBLISHED" == "true" ]]; then | |
echo "Package version ($PACKAGE_VERSION) matches latest published tag ($LATEST_TAG). Aborting build." | |
exit 1 | |
else | |
echo "Package version ($PACKAGE_VERSION) does not match latest published tag ($LATEST_TAG) or the latest tag is a draft. Proceeding with build." | |
fi | |
# - name: Create and push a Git tag | |
# run: | | |
# git tag v$PACKAGE_VERSION | |
# git push origin v$PACKAGE_VERSION | |
- name: Setup node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 22.16.0 | |
- run: echo "🍏 Node setup status is ${{ job.status }}." | |
# Step to set up Python 3.11 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.11' | |
- name: Install dependencies | |
run: | | |
npm install | |
echo "Install's status is ${{ job.status }}." | |
- name: Audit fix | |
run: | | |
npm audit fix | |
echo "Audit fix applied, status is ${{ job.status }}." | |
- name: Set platform-specific ffmpeg path | |
shell: bash | |
run: | | |
PLATFORM="darwin-x64" | |
BINARY="ffmpeg" | |
echo "Platform is $PLATFORM, Binary is $BINARY" | |
# Persist environment variables to the GitHub Actions environment | |
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV | |
echo "BINARY=$BINARY" >> $GITHUB_ENV | |
- name: Modify fluent-ffmpeg processor.js | |
run: | | |
sed -i.bak 's/, 20);/, 5000);/' ./node_modules/fluent-ffmpeg/lib/processor.js && rm -f ./node_modules/fluent-ffmpeg/lib/processor.js.bak | |
# sed -i '' -e '/^\s*setTimeout(function() {/,/}, 20);/c\ | |
# setTimeout(function() {\ | |
# if (ffmpegProc.exitCode === null){\ | |
# emitEnd(new Error('\''Output stream closed'\''));\ | |
# ffmpegProc.kill();\ | |
# }\ | |
# }, 5000);' ./node_modules/fluent-ffmpeg/lib/processor.js | |
grep -A 10 '5000' ./node_modules/fluent-ffmpeg/lib/processor.js | |
shell: bash | |
- name: Patch wavesurfer.js play() to handle AbortError | |
run: | | |
node <<'EOF' | |
const fs = require('fs'); | |
const path = require('path'); | |
const filePath = path.resolve('./node_modules/wavesurfer.js/dist/player.js'); | |
let contents = fs.readFileSync(filePath, 'utf8'); | |
const patched = contents.replace( | |
/return this\.media\.play\(\);/, | |
`try { | |
return this.media.play(); | |
} catch (err) { | |
if (err instanceof DOMException && err.name === 'AbortError') return; | |
throw err; | |
}` | |
); | |
if (patched === contents) { | |
console.error('❌ Wavesurfer patch failed – pattern not found'); | |
process.exit(1); | |
} | |
fs.writeFileSync(filePath, patched); | |
console.log('✅ Patched wavesurfer.js play()'); | |
EOF | |
grep -A 10 'play()' ./node_modules/wavesurfer.js/dist/player.js | |
- name: Modify tracking code | |
run: | | |
# Replace development tracking ID with production ID | |
sed -i.bak '1,30s/const ID_SITE = 3;/const ID_SITE = 2;/' ./js/utils/tracking.js && rm -f ./js/utils/tracking.js.bak | |
grep -A 10 'ID_SITE' ./js/utils/tracking.js | |
shell: bash | |
- name: Build Electron application | |
shell: bash | |
env: | |
ELECTRON_BUILD_ARCH: x64 | |
run: | | |
npm run build-mac-x64-pkg | |
- run: echo "Build status is ${{ job.status }}." | |
- name: Check installer exists | |
shell: bash | |
run: | | |
# Retrieve the version from package.json | |
VERSION=$(jq -r '.version' package.json) | |
# Construct the filename | |
FILENAME="Chirpity-$VERSION.pkg" | |
# Check if the file exists | |
if [ -f "./dist/$FILENAME" ]; then | |
echo "Executable $FILENAME found in ./dist" | |
else | |
echo "Executable $FILENAME not found in ./dist" && exit 1 | |
fi | |
- run: echo "File check status is ${{ job.status }}." | |
# Tests | |
- name: Test packaged application | |
if: runner.os != 'Linux' | |
run: npm test |