forked from MFlowCode/MFC
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (117 loc) · 4.94 KB
/
deploy-tap.yml
File metadata and controls
130 lines (117 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Deploy Homebrew Tap
on:
# Test formula on PRs (audit only, don't deploy)
pull_request:
branches: [ master ]
paths:
- 'packaging/homebrew/mfc.rb'
- 'packaging/homebrew/README.md'
# Deploy to tap on push to master (only when formula files changed)
push:
branches: [ master ]
paths:
- 'packaging/homebrew/mfc.rb'
- 'packaging/homebrew/README.md'
# Deploy to tap when a tag is created (no paths filter on tag creation)
create:
workflow_dispatch:
permissions:
contents: read
jobs:
deploy-tap:
name: Audit and deploy formula
runs-on: macos-14
if: github.event_name != 'create' || github.event.ref_type == 'tag'
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout MFC repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine event metadata
id: meta
run: |
set -euo pipefail
EVENT_NAME="${{ github.event_name }}"
REF_NAME="${{ github.ref_name }}"
if [[ "${EVENT_NAME}" == "create" ]]; then
# Tag creation event
VERSION="${REF_NAME#v}"
URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
elif [[ "${GITHUB_REF_TYPE:-}" == "tag" ]]; then
# Tag push event
VERSION="${REF_NAME#v}"
URL="https://github.com/${{ github.repository }}/archive/refs/tags/v${VERSION}.tar.gz"
else
# Extract URL from current formula to re-audit and sync
URL="$(grep -Eo 'https://github.com/[^"]+/archive/refs/tags/v[0-9]+\.[0-9]+\.[0-9]+\.tar\.gz' packaging/homebrew/mfc.rb | tail -n 1)"
VERSION="$(echo "${URL}" | sed -E 's/.*v([0-9]+\.[0-9]+\.[0-9]+)\.tar\.gz/\1/')"
fi
SHASUM="$(curl -sL "${URL}" | shasum -a 256 | awk '{print $1}')"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "url=${URL}" >> $GITHUB_OUTPUT
echo "sha256=${SHASUM}" >> $GITHUB_OUTPUT
echo "Event: ${EVENT_NAME}" >> $GITHUB_STEP_SUMMARY
echo "Version: ${VERSION}" >> $GITHUB_STEP_SUMMARY
if [[ "${EVENT_NAME}" == "pull_request" ]]; then
echo "Mode: Audit only (PR)" >> $GITHUB_STEP_SUMMARY
else
echo "Mode: Audit and deploy" >> $GITHUB_STEP_SUMMARY
fi
- name: Update formula (for tag events)
if: github.event_name == 'create' || github.ref_type == 'tag'
run: |
/usr/bin/sed -i '' "s@^ url \".*\"@ url \"${{ steps.meta.outputs.url }}\"@" packaging/homebrew/mfc.rb
/usr/bin/sed -i '' "s@^ sha256 \".*\"@ sha256 \"${{ steps.meta.outputs.sha256 }}\"@" packaging/homebrew/mfc.rb
- name: Setup Homebrew
uses: Homebrew/actions/setup-homebrew@master
- name: Audit/style formula before pushing
run: |
brew style packaging/homebrew/mfc.rb
# Create temporary tap to audit the formula
brew tap-new mfc/local
cp packaging/homebrew/mfc.rb "$(brew --repository)/Library/Taps/mfc/homebrew-local/Formula/mfc.rb"
brew audit --online --strict --new --except=homepage mfc/local/mfc || brew audit --online mfc/local/mfc
brew untap mfc/local
- name: Clone or bootstrap tap repository
if: github.event_name != 'pull_request'
env:
TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }}
run: |
set -euo pipefail
REPO="https://x-access-token:${TAP_TOKEN}@github.com/MFlowCode/homebrew-mfc.git"
if git ls-remote "${REPO}" HEAD >/dev/null 2>&1; then
git clone "${REPO}" tap-repo
else
# Repo exists but might be empty; fall back to bootstrap
mkdir -p tap-repo
cd tap-repo
git init -b main
git remote add origin "${REPO}"
touch .keep
git add .keep
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" commit -m "Initialize tap"
git push -u origin main
fi
- name: Copy formula and README into tap
if: github.event_name != 'pull_request'
run: |
mkdir -p tap-repo/Formula
cp packaging/homebrew/mfc.rb tap-repo/Formula/mfc.rb
cp packaging/homebrew/README.md tap-repo/README.md
- name: Commit & push if changed
if: github.event_name != 'pull_request'
env:
TAP_TOKEN: ${{ secrets.TAP_REPO_TOKEN }}
run: |
cd tap-repo
git add Formula/mfc.rb README.md
if git diff --cached --quiet; then
echo "No changes in Formula/mfc.rb or README.md; skipping push."
exit 0
fi
git -c user.name="github-actions[bot]" -c user.email="github-actions[bot]@users.noreply.github.com" \
commit -m "mfc: v${{ steps.meta.outputs.version }}"
git push origin HEAD:main