Update Data #1452
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update Data | |
on: | |
schedule: | |
# Run every hour | |
- cron: '0 */2 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
pull-requests: write | |
concurrency: | |
cancel-in-progress: true | |
group: ${{ github.workflow }} | |
env: | |
nix_path: nixpkgs=channel:nixos-24.05 | |
jobs: | |
update-data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup Nix | |
uses: cachix/install-nix-action@v25 | |
with: | |
nix_path: "${{ env.nix_path }}" | |
- name: Setup cachix | |
uses: cachix/cachix-action@v14 | |
with: | |
name: cofob | |
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" | |
- name: Start hidden services | |
run: | | |
nohup nix-shell -p tor --run tor & | |
nohup nix-shell -p i2pd --run i2pd & | |
echo "Wait for tor and i2pd to start" | |
sleep 120 | |
- name: Checkout the data branch | |
uses: actions/checkout@v4 | |
with: | |
ref: data | |
fetch-depth: 1 | |
- name: Get services.json from master branch | |
run: git fetch origin master && git checkout origin/master -- services.json | |
- name: Actualize data.json | |
run: | | |
nix run github:cofob/fastside#actualizer -- \ | |
-c config.yml \ | |
actualize \ | |
--max-parallel 25 -d data.json services.json | |
- name: Commit and push changes to data branch | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add data.json services.json | |
git commit -m "Update data.json and services.json [no ci]" || true | |
- name: Push changes to data | |
uses: ad-m/github-push-action@master | |
continue-on-error: true | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: data | |
- name: Update master branch | |
run: | | |
CURRENT_HOUR=$(date +'%H') | |
echo "Current hour: $CURRENT_HOUR" | |
if [ "$CURRENT_HOUR" -eq 0 ]; then | |
echo "It's midnight, commit to master" | |
git checkout master | |
git fetch origin data | |
git checkout origin/data -- services.json | |
git add services.json | |
git commit -m "Update services.json from data branch" || true | |
git push origin master | |
fi | |
- name: Remove historical data | |
run: | | |
CURRENT_HOUR=$(date +'%H') | |
echo "Current hour: $CURRENT_HOUR" | |
if [ "$CURRENT_HOUR" -eq 0 ]; then | |
CURRENT_DAY=$(date +'%u') | |
echo "Current day: $CURRENT_DAY" | |
if [ "$CURRENT_DAY" -eq 1 ]; then | |
echo "It's Monday, remove historical data" | |
git checkout data | |
git reset --hard HEAD | |
git checkout --orphan cleared-data | |
git add -A | |
git commit -m "Remove historical data" | |
git branch -D data | |
git branch -m data | |
git push origin data --force | |
fi | |
fi |