Skip to content

make sure to add a github token so the script can delete old releases #4

make sure to add a github token so the script can delete old releases

make sure to add a github token so the script can delete old releases #4

Workflow file for this run

name: Upload Arrow Files to Latest Release
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
upload-arrow-files:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v3
- name: Check if Arrow files are modified
id: arrow_files_modified
run: |
# List modified files in the PR
base_commit=$(git merge-base HEAD main)
modified_files=$(git diff --name-only "$base_commit" HEAD)
# Check if any Arrow files were modified (based on their file extension or path)
if echo "$modified_files" | grep -qE "\.arrow$"; then
echo "Arrow files were modified."
echo "arrow_files_modified=true" >> $GITHUB_ENV
else
echo "No Arrow files were modified."
echo "arrow_files_modified=false" >> $GITHUB_ENV
fi
- name: Pull Git LFS Files
if: env.arrow_files_modified == 'true'
run: |
# git lfs install
git lfs pull
- name: Get Incremented EJAMDATA Release Tag
if: env.arrow_files_modified == 'true'
run: |
# Get the latest release tag from the current repo
latest_tag=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
# If no release exists, start with v0.1.0
if [ "$latest_tag" == "null" ]; then
new_ejamdata_tag="v0.1.0"
else
# Increment the version (Assuming version format is like v1.2.3)
new_ejamdata_tag=$(echo "$latest_tag" | awk -F. -v OFS=. '{ $NF++; print $0 }')
fi
- name: Create New EJAMData Release
if: env.arrow_files_modified == 'true'
run: |
gh release create ${{ env.new_tag }} -t ${{ env.new_tag }} -n "Automated release for Arrow files"
- name: Upload Arrow Files to New Release
if: env.arrow_files_modified == 'true'
run: |
gh release upload ${{ env.new_tag }} '**/*.arrow'
# keep storage low
- name: Delete Older Releases (Keep Last 3)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get the list of all release tags sorted by date (excluding the latest 3)
old_releases=$(gh release list --limit 100 --json tagName -q '.[3:].tagName')
# Loop through and delete each old release
for tag in $old_releases; do
echo "Deleting release: $tag"
gh release delete $tag --yes
done