using GITHUB_REF for base commit, and GITHUB_SHA for current commit #11
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: 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@v4 | |
- 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) | |
echo "Base commit: $GITHUB_REF" | |
echo "Current HEAD commit: $GITHUB_SHA" | |
modified_files=$(git diff --name-only "$base_commit" "$GITHUB_REF") | |
echo "Modified files: $modified_files" | |
# 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) | |
total_releases=$(gh release list --limit 100 --json tagName -q 'length') | |
# Check if old_releases is empty | |
if [[ "$total_releases" -le 1 ]]; then | |
exit 0 | |
fi | |
# Get the list of old releases (excluding the latest 3) | |
old_releases=$(gh release list --limit 100 --json tagName -q '.[1:].tagName') | |
# Loop through and delete each old release | |
for tag in $old_releases; do | |
echo "Deleting old release: $tag" | |
gh release delete $tag --yes | |
done |