Skip to content

Update MAIDR Bundle #56

Update MAIDR Bundle

Update MAIDR Bundle #56

name: Update MAIDR Bundle
on:
schedule:
# Run daily at 9 AM UTC
- cron: '0 9 * * *'
workflow_dispatch:
# Allow manual triggering
permissions:
contents: write
jobs:
check-and-update:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup R
uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
- name: Install R dependencies
run: |
install.packages(c('jsonlite', 'rprojroot'))
shell: Rscript {0}
- name: Get latest MAIDR version from npm
id: npm-version
run: |
LATEST_VERSION=$(curl -s https://registry.npmjs.org/maidr/latest | jq -r '.version')
echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT
echo "Latest MAIDR version: $LATEST_VERSION"
- name: Get current bundled version
id: current-version
run: |
CURRENT_VERSION=$(grep 'MAIDR_VERSION <-' R/html_dependencies.R | sed 's/.*"\(.*\)".*/\1/')
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current bundled version: $CURRENT_VERSION"
- name: Check if update needed
id: check-update
run: |
if [ "${{ steps.npm-version.outputs.version }}" != "${{ steps.current-version.outputs.version }}" ]; then
echo "needs_update=true" >> $GITHUB_OUTPUT
echo "Update needed: ${{ steps.current-version.outputs.version }} -> ${{ steps.npm-version.outputs.version }}"
else
echo "needs_update=false" >> $GITHUB_OUTPUT
echo "Already up to date"
fi
- name: Download new MAIDR assets
if: steps.check-update.outputs.needs_update == 'true'
run: |
Rscript tools/update-maidr-assets.R ${{ steps.npm-version.outputs.version }}
- name: Update version in R code
if: steps.check-update.outputs.needs_update == 'true'
run: |
VERSION="${{ steps.npm-version.outputs.version }}"
OLD_VERSION="${{ steps.current-version.outputs.version }}"
# Update R/html_dependencies.R
sed -i 's/MAIDR_VERSION <- "[^"]*"/MAIDR_VERSION <- "'"$VERSION"'"/' R/html_dependencies.R
echo "Updated R/html_dependencies.R"
# Update inst/htmlwidgets/maidr.yaml
sed -i "s/version: .*/version: $VERSION/" inst/htmlwidgets/maidr.yaml
sed -i "s|src: htmlwidgets/lib/maidr-.*|src: htmlwidgets/lib/maidr-$VERSION|" inst/htmlwidgets/maidr.yaml
echo "Updated inst/htmlwidgets/maidr.yaml"
# Show changes
echo "=== Changes ==="
git diff --stat
- name: Commit and push changes
if: steps.check-update.outputs.needs_update == 'true'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "chore: update MAIDR bundle to v${{ steps.npm-version.outputs.version }}"
commit_user_name: "github-actions[bot]"
commit_user_email: "github-actions[bot]@users.noreply.github.com"
file_pattern: "R/html_dependencies.R inst/htmlwidgets/"