-
Notifications
You must be signed in to change notification settings - Fork 5
138 lines (113 loc) · 4.93 KB
/
build.yml
File metadata and controls
138 lines (113 loc) · 4.93 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
130
131
132
133
134
135
136
137
138
name: CI
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: "0 */2 * * *"
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
update_available: ${{ steps.update_available.outputs.update_status }}
ophirofox_version: ${{ steps.get_ophirofox_version.outputs.version }}
ophirofox_version_raw: ${{ steps.get_ophirofox_version.outputs.version_raw }}
steps:
- id: current_repo
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Get latest ophirofox version from 'current' tag"
id: get_ophirofox_version
continue-on-error: true
run: |
# Get the release info for the 'current' tag
RELEASE_INFO=$(curl -s https://api.github.com/repos/lovasoa/ophirofox/releases/tags/current)
# Extract version from release name (format: "Current Build (vX.Y.Z.W) - Signed/Unsigned")
OPHIROFOX_VERSION_RAW=$(echo "$RELEASE_INFO" | jq -r '.name' | grep -oP 'v[\d.]+')
OPHIROFOX_VERSION=$(echo "$OPHIROFOX_VERSION_RAW" | cut -c2-)
echo "version_raw=$OPHIROFOX_VERSION_RAW" >> $GITHUB_OUTPUT
echo "version=$OPHIROFOX_VERSION" >> $GITHUB_OUTPUT
echo "Found Ophirofox version: $OPHIROFOX_VERSION_RAW ($OPHIROFOX_VERSION)"
- id: update_available
if: steps.get_ophirofox_version.outcome == 'success'
run: |
echo CURRENT REPO RELEASE : ${{ steps.current_repo.outputs.release }}
echo OPHIROFOX REPO RELEASE : ${{ steps.get_ophirofox_version.outputs.version_raw }}
if [[ "${{ steps.current_repo.outputs.release }}" == "${{ steps.get_ophirofox_version.outputs.version_raw }}" ]]; then
echo "No release available"
echo "update_status=false" >> $GITHUB_OUTPUT
else
echo "New release available"
echo "update_status=true" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
needs: check-version
if: ${{ needs.check-version.outputs.update_available == 'true' }}
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Download ophirofox source from 'current' tag"
run: |
# Clone the repo and checkout the 'current' tag
git clone --depth 1 --branch current https://github.com/lovasoa/ophirofox.git ophirofox
- name: Copy generate-userscript.sh inside ophirofox dir
run: cp ./generate-userscript.sh ./ophirofox/generate-userscript.sh
- name: Grant execution rights to generate-userscript.sh
working-directory: ophirofox
run: chmod +x ./generate-userscript.sh
- name: Run generate-userscript.sh
working-directory: ophirofox
run: bash ./generate-userscript.sh ${{ needs.check-version.outputs.ophirofox_version }} || true
- name: Debug file existence
run: |
ls -la ./ophirofox/
echo "Does file exist?"
if [ -f "./ophirofox/ophirofox.user.js" ]; then echo "Yes"; else echo "No"; fi
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install jsbeautifier via pip
working-directory: ophirofox
run: pip install jsbeautifier
- name: Beautify userscript
working-directory: ophirofox
run: js-beautify ophirofox.user.js >> ophirofox-pretty.user.js && mv ophirofox-pretty.user.js ophirofox.user.js
- name: Get ophirofox changelog from 'current' release
run: |
curl -s https://api.github.com/repos/lovasoa/ophirofox/releases/tags/current | jq -r '.body' | tee /tmp/changelog.txt
- name: Push to main
run: |
cp ./ophirofox/ophirofox.user.js .
git config user.name github-actions
git config user.email github-actions@github.com
git add ophirofox.user.js
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Release from Ophirofox ${{ needs.check-version.outputs.ophirofox_version_raw }}"
git push
fi
- name: Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.check-version.outputs.ophirofox_version_raw }}
name: Release ${{ needs.check-version.outputs.ophirofox_version }}
token: ${{ secrets.GITHUB_TOKEN }}
draft: false
prerelease: false
body_path: /tmp/changelog.txt
files: |
./ophirofox/ophirofox.user.js
/tmp/changelog.txt