1+ name : Fetch Latest Bandicoot Release
2+
3+ on :
4+ workflow_dispatch : # Manual trigger
5+ schedule :
6+ - cron : ' 0 17 * * *' # Runs daily at 10 AM PDT (5 PM UTC)
7+
8+ jobs :
9+ fetch-gitlab-release :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout repository
14+ uses : actions/checkout@v3
15+
16+ - name : Set up GitLab API access
17+ id : setup
18+ run : |
19+ echo "GITLAB_API_URL=https://gitlab.com/api/v4" >> $GITHUB_ENV
20+ echo "GITLAB_PROJECT_ID=bandicoot-lib/bandicoot-code" >> $GITHUB_ENV
21+
22+ - name : Get current version
23+ id : current-version
24+ run : |
25+ if [ -f "inst/version.txt" ]; then
26+ CURRENT_VERSION=$(cat inst/version.txt)
27+ echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
28+ echo "Current version: $CURRENT_VERSION"
29+ else
30+ echo "current_version=none" >> $GITHUB_OUTPUT
31+ echo "No current version found"
32+ fi
33+
34+ - name : Fetch latest release from GitLab
35+ id : get-version
36+ run : |
37+ # Fetch latest release from GitLab API
38+ RESPONSE=$(curl -s "$GITLAB_API_URL/projects/$(echo $GITLAB_PROJECT_ID | sed 's/\//%2F/g')/releases" \
39+ -H "PRIVATE-TOKEN: ${{ secrets.GITLAB_API_TOKEN }}")
40+
41+ # Extract the latest version and download URL
42+ LATEST_VERSION=$(echo $RESPONSE | jq -r '.[0].tag_name')
43+ DOWNLOAD_URL=$(echo $RESPONSE | jq -r '.[0].assets.sources[0].url')
44+
45+ # Remove 'v' prefix if present
46+ LATEST_VERSION=${LATEST_VERSION#v}
47+
48+ # Set as output and environment variable
49+ echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
50+ echo "download_url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
51+ echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
52+
53+ # Log the fetched version
54+ echo "Latest version: $LATEST_VERSION"
55+ echo "Download URL: $DOWNLOAD_URL"
56+
57+ - name : Check if update is needed
58+ id : check-update
59+ run : |
60+ if [ "${{ steps.current-version.outputs.current_version }}" != "${{ steps.get-version.outputs.version }}" ]; then
61+ echo "update_needed=true" >> $GITHUB_OUTPUT
62+ echo "Update needed: Current version ${{ steps.current-version.outputs.current_version }} differs from latest ${{ steps.get-version.outputs.version }}"
63+ else
64+ echo "update_needed=false" >> $GITHUB_OUTPUT
65+ echo "No update needed: Current version matches latest version"
66+ fi
67+
68+ - name : Download and extract release
69+ if : steps.check-update.outputs.update_needed == 'true'
70+ run : |
71+ # Create temporary directory
72+ mkdir -p temp_download
73+
74+ # Download the release tarball
75+ curl -L "${{ steps.get-version.outputs.download_url }}" -o temp_download/release.tar.gz
76+
77+ # Extract the release tarball
78+ tar -xzf temp_download/release.tar.gz -C temp_download
79+
80+ # Create destination directory if it doesn't exist
81+ mkdir -p inst/include
82+
83+ # Find and copy the include directory contents
84+ find temp_download -name "include" -type d -exec cp -r {}/* inst/include/ \;
85+
86+ # Clean up
87+ rm -rf temp_download
88+
89+ # Update version file
90+ mkdir -p inst
91+ echo "${{ steps.get-version.outputs.version }}" > inst/version.txt
92+
93+ - name : Create Pull Request
94+ if : steps.check-update.outputs.update_needed == 'true'
95+ uses : peter-evans/create-pull-request@v5
96+ with :
97+ token : ${{ secrets.GITHUB_TOKEN }}
98+ commit-message : " Update to Bandicoot release ${{ steps.get-version.outputs.version }}"
99+ title : " Update Bandicoot to version ${{ steps.get-version.outputs.version }}"
100+ body : |
101+ This PR updates the Bandicoot library from version ${{ steps.current-version.outputs.current_version }} to ${{ steps.get-version.outputs.version }}.
102+
103+ Changes:
104+ - Updated `inst/include/` files from the latest release
105+ - Updated version in `inst/version.txt`
106+
107+ This PR was automatically generated by the Fetch Latest Bandicoot Release workflow.
108+ branch : update-bandicoot-${{ steps.get-version.outputs.version }}
109+ base : main
110+ labels : |
111+ dependency
112+ automated pr
0 commit comments