Repository navigation
106 lines (99 loc) · 3.63 KB
/
Copy pathupdate.yml
File metadata and controls
106 lines (99 loc) · 3.63 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
name: Update stable release
on:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: update-stable
cancel-in-progress: false
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.update.outputs.changed }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- name: Resolve latest stable release
id: update
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 -m unittest discover -s tests
python3 scripts/update.py
if ! git diff --quiet -- Casks/opentubex.rb; then
echo 'changed=true' >> "$GITHUB_OUTPUT"
fi
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: steps.update.outputs.changed == 'true'
with:
name: cask
path: Casks/opentubex.rb
test:
needs: prepare
if: needs.prepare.outputs.changed == 'true'
strategy:
fail-fast: false
matrix:
os: [macos-15, macos-15-intel]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: cask
path: Casks
- name: Install the candidate cask into the local tap
run: |
brew tap opentubex/tap "$GITHUB_WORKSPACE"
cp Casks/opentubex.rb "$(brew --repository opentubex/tap)/Casks/opentubex.rb"
- run: brew style --cask opentubex/tap/opentubex
- run: brew install --cask opentubex/tap/opentubex
- run: bash scripts/test-install.sh
publish:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.sha }}
persist-credentials: false
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: cask
path: Casks
- name: Publish tested cask with a GitHub-signed commit
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 - <<'PY'
import base64
import json
import os
from pathlib import Path
import re
import subprocess
path = 'Casks/opentubex.rb'
endpoint = f'repos/{os.environ["GITHUB_REPOSITORY"]}/contents/{path}'
current = json.loads(subprocess.check_output(['gh', 'api', endpoint]))
source = Path(path).read_bytes()
if source == base64.b64decode(current['content']):
print('Cask is already current')
raise SystemExit(0)
# Do not overwrite a cask changed while the macOS checks were running.
expected = subprocess.check_output(['git', 'rev-parse', f'HEAD:{path}'], text=True).strip()
if current['sha'] != expected:
raise SystemExit('Cask changed during validation; rerun this workflow')
version = re.search(rb' version "([^"]+)"', source)[1].decode()
payload = {'message': f'chore: update OpenTubeX to {version}',
'content': base64.b64encode(source).decode(), 'sha': current['sha']}
subprocess.run(['gh', 'api', '--method', 'PUT', endpoint, '--input', '-', '--silent'],
input=json.dumps(payload), text=True, check=True)
PY