Skip to content
69 changes: 69 additions & 0 deletions .github/workflows/Snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Monthly Snapshot

on:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *' # Runs at 00:00 UTC on the 1st of every month

jobs:
snapshot:
runs-on: ubuntu-latest

steps:
- name: Checkout repo with submodules
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set date variables
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"

- name: Install zstd/rsync
run: sudo apt-get update && sudo apt-get install -y zstd rsync

- name: Create a temporary directory for snapshot
run: |
mkdir -p /tmp/snapshot
rsync -av --exclude='.git' --exclude='.gitmodules' --exclude='.github' ./ /tmp/snapshot/
rm -rf *

- name: Create tar.zst snapshot
run: |
cd /tmp/snapshot
tar -I 'zstd -T0 -19' -cvf "$GITHUB_WORKSPACE/Flipper-${{ steps.date.outputs.date }}.tar.zst" *

- name: Upload snapshot artifact
uses: actions/upload-artifact@v4
with:
name: snapshot
path: Flipper-${{ steps.date.outputs.date }}.tar.zst

- name: Check if archive > 2GB and split if needed
id: check_size
run: |
file="Flipper-${{ steps.date.outputs.date }}.tar.zst"
max_size=$((2 * 1024 * 1024 * 1024)) # 2GB in bytes
actual_size=$(stat -c%s "$file")
if [ "$actual_size" -ge "$max_size" ]; then
split -b 1996M "$file" "${file}."
echo "split=true" >> "$GITHUB_OUTPUT"
else
echo "split=false" >> "$GITHUB_OUTPUT"
fi

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: "Snapshot ${{ steps.date.outputs.date }}"
tag_name: "Snapshot-${{ steps.date.outputs.date }}"
body: |
Automated snapshot for ${{ steps.date.outputs.date }}.
Note: If archive was split due to size >2GB use cat to join them together
```
cat Flipper-${{ steps.date.outputs.date }}.tar.zst.* > Flipper-${{ steps.date.outputs.date }}.tar.zst
```
files: |
${{ steps.check_size.outputs.split == 'true' && format('Flipper-{0}.tar.zst.*', steps.date.outputs.date) || format('Flipper-{0}.tar.zst', steps.date.outputs.date) }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}