Skip to content

CI

CI #17431

Workflow file for this run

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 */1 * * *"
# 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
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: ./generate-userscript.sh ${{ needs.check-version.outputs.ophirofox_version }}
- 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