mirror of
https://github.com/TrianguloY/UrlChecker.git
synced 2024-09-20 04:12:14 +02:00
Assets update action (#110)
This action updates assets files, currently there is only one asset file, the ClearURLs catalog, but the action can be easily expanded if more are added ( maybe these issues can benefit from it: #82 #61 #10 #7 ), just copy and paste the ClearURLS catalog step and change the enviroment variables. Co-authored-by: Ilithy <36798218+Ilithy@users.noreply.github.com>
This commit is contained in:
parent
e29b3dccbb
commit
90ea9235dd
48
.github/scripts/file-updater.sh
vendored
Normal file
48
.github/scripts/file-updater.sh
vendored
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
# Retrieve parameters
|
||||||
|
fileName=$1
|
||||||
|
fileURL=$2
|
||||||
|
path=$3
|
||||||
|
hashURL=$4
|
||||||
|
|
||||||
|
# Temporal folder to work on
|
||||||
|
# Needed in case a file is updated in the main folder, and the hash checking fails
|
||||||
|
downloadFolder="./.file_updater_action_temporal_folder/"
|
||||||
|
mkdir $downloadFolder
|
||||||
|
tempPath="$downloadFolder$fileName"
|
||||||
|
|
||||||
|
# Store checksum
|
||||||
|
curlHashExit=1
|
||||||
|
if [ "$path" != "" ]; then
|
||||||
|
checksum=$(curl $hashURL)
|
||||||
|
curlHashExit=$?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Avoid download of same file
|
||||||
|
oldFileChecksum=$(sha256sum "$path$fileName")
|
||||||
|
if [ "$oldFileChecksum" = "$checksum $path$fileName" ]; then
|
||||||
|
echo "Current file checksum is the same as the new one"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Download file
|
||||||
|
curl "$fileURL" -o $tempPath
|
||||||
|
curlFileExit=$?
|
||||||
|
|
||||||
|
# If both downloads were succesful
|
||||||
|
if [[ $curlFileExit -eq 0 && $curlHashExit -eq 0 ]]; then
|
||||||
|
# Checksum of file
|
||||||
|
dlFileChecksum=$(sha256sum $tempPath)
|
||||||
|
# If matches
|
||||||
|
if [ "$dlFileChecksum" = "$checksum $tempPath" ]; then
|
||||||
|
mv $tempPath "$path$fileName"
|
||||||
|
# No need to check exit code, if mv fails GitHub actions will too
|
||||||
|
else
|
||||||
|
# If not, failure
|
||||||
|
echo "Hash does not match" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# If not, failure
|
||||||
|
echo "Downloads failed" >&2
|
||||||
|
exit 3
|
||||||
|
fi
|
60
.github/workflows/assets-updater.yml
vendored
Normal file
60
.github/workflows/assets-updater.yml
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
# This action updates assets files
|
||||||
|
name: Assets updater
|
||||||
|
|
||||||
|
on:
|
||||||
|
# weekly
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * Sun'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
download:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
workingBranch: assets-updater-action
|
||||||
|
steps:
|
||||||
|
- name: Checkout main
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Git config
|
||||||
|
run: |
|
||||||
|
git config user.name 'github-actions[bot]'
|
||||||
|
git config user.email 'github-actions[bot]@users.noreply.github.com'
|
||||||
|
|
||||||
|
- name: Check if branch exists
|
||||||
|
run: |
|
||||||
|
count=($(git ls-remote --heads origin "$workingBranch" | wc))
|
||||||
|
if [[ ${count[0]} -ne 0 ]]; then
|
||||||
|
# Exists
|
||||||
|
git fetch
|
||||||
|
git checkout -b $workingBranch "origin/$workingBranch"
|
||||||
|
else
|
||||||
|
# Does not exist
|
||||||
|
git checkout -b $workingBranch
|
||||||
|
git push --set-upstream origin $workingBranch
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: ClearURLs catalog
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
bash ./.github/scripts/file-updater.sh $fileName $fileURL $filePath $hashURL
|
||||||
|
git add "$filePath$fileName"
|
||||||
|
git commit -m "$message"
|
||||||
|
git push
|
||||||
|
echo "$fileName commited successfully"
|
||||||
|
env:
|
||||||
|
fileName: "data.minify.json"
|
||||||
|
fileURL: "https://rules2.clearurls.xyz/data.min.json"
|
||||||
|
filePath: "./app/src/main/assets/"
|
||||||
|
hashURL: "https://rules2.clearurls.xyz/rules.min.hash"
|
||||||
|
message: "ClearURLs catalog updated"
|
||||||
|
|
||||||
|
- name: Pull request
|
||||||
|
run:
|
||||||
|
gh pr create --title 'Automated assets updater action' --body ''
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
Loading…
Reference in New Issue
Block a user