Skip to content

Download build artifacts for homebrew update #23

Download build artifacts for homebrew update

Download build artifacts for homebrew update #23

name: 🏗️ CI/CD
on: push
jobs:
build:
name: 🛠️ Build
runs-on: macos-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 🔨 Build Xcode project
uses: sersoft-gmbh/xcodebuild-action@v3
with:
project: Switcher.xcodeproj
scheme: Switcher
destination: platform=macOS
configuration: Release
action: build
build-settings: CONFIGURATION_BUILD_DIR=build/Release
- name: 💿 Create .dmg
run: |
mkdir -p build/dmg/Switcher
cp -R build/Release/Switcher.app build/dmg/Switcher/
ln -s /Applications build/dmg/Switcher/Applications
hdiutil create -volname Switcher \
-srcfolder build/dmg/Switcher \
-ov -format UDRO \
build/dmg/Switcher-${{ github.ref_type == 'tag' && github.ref_name || github.sha }}.dmg
- name: 💎 Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: Switcher-Build
path: build/dmg/Switcher-${{ github.ref_type == 'tag' && github.ref_name || github.sha }}.dmg
release:
name: 🚀 Release
needs: build
if: github.ref_type == 'tag'
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: 📥 Checkout code
uses: actions/checkout@v4
- name: 📝 Generate release changelog
id: changelog_step
uses: janheinrichmerker/action-github-changelog-generator@v2.3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: 📦 Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: Switcher-Build
- name: 🎈 Create or Update GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog_step.outputs.changelog }}
files: Switcher-${{ github.ref_name }}.dmg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update-homebrew-tap:
runs-on: ubuntu-latest
needs: release
steps:
# I have no idea if it's actually necessary to install Git on the runner
# but checkout didn't work with available version over SSH.
# this is just the first configuration that worked for me.
# So, doing everything manually.
- name: 🛠️ Install Git
run: |
sudo apt update
sudo apt install -y git
- name: 🛠️ Setup Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: 🔑 Add GitHub to Known Hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
- name: 🔑 Setup SSH Agent
run: |
sudo apt install -y openssh-client
echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
- name: 🛠️ Checkout Homebrew Tap Repo
run : |
git clone git@github.com:Bobronium/homebrew-tap.git .
- name: 📦 Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: Switcher-Build
- name: 🔍 Calculate Checksum
run: |
sha256sum Switcher-${{ github.ref_name }}.dmg | awk '{ print $1 }' > /tmp/checksum
formula_file="Casks/switcher.rb"
tag="${{ github.ref_name }}"
checksum="$(cat /tmp/checksum)"
sed -i "s|version \".*\"|version \"${tag#v}\"|" "$formula_file"
sed -i "s|sha256 \".*\"|sha256 \"$checksum\"|" "$formula_file"
- name: 🚀 Commit and Push Changes
run: |
git add Casks/switcher.rb
git commit -m "Bump version to ${{ github.ref_name }}"
git push