Update FPS Shops Data #75
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 FPS Shops Data | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs daily at midnight UTC | |
workflow_dispatch: | |
push: | |
jobs: | |
update_fps_shops: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Cache pip dependencies | |
uses: actions/cache@v4 | |
id: cache-pip | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
if: steps.cache-pip.outputs.cache-hit != 'true' | |
run: | | |
python -m pip install --upgrade pip | |
pip install aiohttp pandas | |
- name: Download previous release artifact | |
run: | | |
latest_release=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest) | |
asset_url=$(echo $latest_release | jq -r '.assets[0].browser_download_url') | |
if [ "$asset_url" != "null" ]; then | |
curl -L -o previous_ConsolidatedShops.csv $asset_url | |
echo "Previous artifact downloaded." | |
else | |
echo "No previous release found." | |
fi | |
- name: Run FPS data extraction and comparison | |
run: | | |
python script.py | |
if [ -f "previous_ConsolidatedShops.csv" ]; then | |
python compare_data.py || echo "changes=N/A" >> $GITHUB_ENV | |
else | |
echo "No previous data found. Skipping comparison." | |
echo "changes=N/A" >> $GITHUB_ENV | |
fi | |
- name: Check for changes | |
run: | | |
if [ "${{ env.changes }}" != "N/A" ] && \ | |
echo "${{ env.changes }}" | grep -q "Added Shops: 0" && \ | |
echo "${{ env.changes }}" | grep -q "Removed Shops: 0" && \ | |
echo "${{ env.changes }}" | grep -q "Updated Shops: 0"; then | |
echo "no_changes=true" >> $GITHUB_ENV | |
fi | |
env: | |
changes: ${{ steps.compare-data.outputs.changes }} | |
- name: Upload ConsolidatedShops.csv artifact | |
if: env.no_changes != 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ConsolidatedShops.csv | |
path: ConsolidatedShops.csv | |
- name: Set tag name to current timestamp | |
run: | | |
NOW=$(date +'%Y%m%d%H%M%S') | |
TAG_NAME="v${NOW}" | |
echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV | |
- name: Create release with notes | |
if: env.no_changes != 'true' | |
uses: softprops/action-gh-release@v2 | |
with: | |
files: ConsolidatedShops.csv | |
tag_name: "${{ env.TAG_NAME }}" | |
make_latest: true | |
body: | | |
Daily update of FPS Shops data. | |
Changes: | |
${{ steps.compare-data.outputs.changes }} | |
token: ${{ secrets.GITHUB_TOKEN }} |