Skip to content

Update Ensmallen

Update Ensmallen #881

name: Update Ensmallen
on:
workflow_dispatch:
schedule:
- cron: '0 10 * * *'
jobs:
updateEnsmallen:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get Latest Ensmallen Tagged Release
id: ensmallen-lib
run: |
# Ping version information upstream
ENSMALLEN_RELEASE_JSON=$(curl -sL https://api.github.com/repos/mlpack/ensmallen/releases/latest)
ENSMALLEN_RELEASE_VERSION=$(jq -r ".tag_name" <<< "$ENSMALLEN_RELEASE_JSON")
ENSMALLEN_RELEASE_DATE=$(jq -r ".published_at" <<< "$ENSMALLEN_RELEASE_JSON" | sed 's/T.*//g')
echo "release_tag=$(echo $ENSMALLEN_RELEASE_VERSION)" >> $GITHUB_OUTPUT
echo "release_date=$(echo $ENSMALLEN_RELEASE_DATE)" >> $GITHUB_OUTPUT
# Extract out version information from git repository
ENSMALLEN_VERSION_MAJOR=$(grep -i ".*#define ENS_VERSION_MAJOR.*" inst/include/ensmallen_bits/ens_version.hpp | grep -o "[0-9]*")
ENSMALLEN_VERSION_MINOR=$(grep -i ".*#define ENS_VERSION_MINOR.*" inst/include/ensmallen_bits/ens_version.hpp | grep -o "[0-9]*")
ENSMALLEN_VERSION_PATCH=$(grep -i ".*#define ENS_VERSION_PATCH.*" inst/include/ensmallen_bits/ens_version.hpp | grep -o "[0-9]*")
# Combine values to match release tag information
ENSMALLEN_VERSION_VALUE=${ENSMALLEN_VERSION_MAJOR}.${ENSMALLEN_VERSION_MINOR}.${ENSMALLEN_VERSION_PATCH}
# Set the current release tag
echo "current_tag=$(echo $ENSMALLEN_VERSION_VALUE)" >> $GITHUB_OUTPUT
- name: Update Ensmallen
if: steps.ensmallen-lib.outputs.current_tag != steps.ensmallen-lib.outputs.release_tag
env:
CURRENT_TAG: ${{ steps.ensmallen-lib.outputs.current_tag }}
RELEASE_TAG: ${{ steps.ensmallen-lib.outputs.release_tag }}
RELEASE_DATE: ${{ steps.ensmallen-lib.outputs.release_date }}
run: |
# Delete the dist directory and index.html
rm -fr inst/include/ensmallen_bits inst/include/ensmallen.hpp
# Download the release
curl -sL -o $RELEASE_TAG https://api.github.com/repos/mlpack/ensmallen/tarball/$RELEASE_TAG
# Get the prefix directory coded to commit version to access
# specific files in the tar e.g. mlpack-ensmallen-0431e31
TAR_PREFIX_DIR=$(tar -tzf $RELEASE_TAG | head -1 | cut -f1 -d"/")
# Extract the update files directly into the include directory.
# Strip away two levels ${TAR_PREFIX_DIR}/include.
tar -xzf $RELEASE_TAG -C inst/include/ --strip-components=2 ${TAR_PREFIX_DIR}/include/ensmallen_bits ${TAR_PREFIX_DIR}/include/ensmallen.hpp
# Extract HISTORY.md file into the tool directory for a comparison.
# Strip away one-level ${TAR_PREFIX_DIR}
tar -xzf $RELEASE_TAG -C tools/ --strip-components=1 ${TAR_PREFIX_DIR}/HISTORY.md
# Begin work on formatting NEWS entry
# Obtain the double quoted version name
ENSMALLEN_VERSION_NAME=$(grep -i ".*#define ENS_VERSION_NAME.*" inst/include/ensmallen_bits/ens_version.hpp | grep -o '".*"')
NEW_RCPPENSMALLEN_VERSION=0.${RELEASE_TAG}.1
# Extract out the new changes using diff
# Steps: Remove blank lines, delete header, replace * with -, indent by 1
NEWS_UPDATE=$(diff --unchanged-group-format="" tools/HISTORY.md tools/HISTORYold.md | sed '/^$/d' | sed '/^#/d' | sed 's/\*/-/' | sed 's/^/ /')
# Set the new history to be old
mv tools/HISTORY.md tools/HISTORYold.md
# Prepend new update notes to NEWS.md with a heredoc
cat <<-EOF > NEWS.md
# RcppEnsmallen ${NEW_RCPPENSMALLEN_VERSION}
- Upgraded to ensmallen ${RELEASE_TAG}: ${ENSMALLEN_VERSION_NAME} ($RELEASE_DATE)
${NEWS_UPDATE}
$(cat NEWS.md)
EOF
# Update R package version
sed -i "s/Version:.*/Version: ${NEW_RCPPENSMALLEN_VERSION}/g" DESCRIPTION
# Prepend entry to ChangeLog with a heredoc
TAB="$(printf '\t')"
cat <<-EOF > ChangeLog
$(date +"%Y-%m-%d") James Balamuta <balamut2@illinois.edu>
${TAB}* DESCRIPTION (Version): Release ${RELEASE_TAG}
${TAB}* NEWS.md: Update for Ensmallen release ${RELEASE_TAG}
${TAB}* inst/include/ensmallen_bits: Upgraded to Ensmallen ${RELEASE_TAG}
${TAB}* inst/include/ensmallen.hpp: ditto
$(cat ChangeLog)
EOF
# Remove the release tar.gz
rm $RELEASE_TAG
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
commit-message: Upgrade ensmallen to ${{ steps.ensmallen-lib.outputs.release_tag }}
title: Upgrade ensmallen to ${{ steps.ensmallen-lib.outputs.release_tag }}
body: |
Updates [mlpack/ensmallen][1] to ${{ steps.ensmallen-lib.outputs.release_tag }}.
Auto-generated by [create-pull-request][2]
[1]: https://github.com/mlpack/ensmallen
[2]: https://github.com/peter-evans/create-pull-request
labels: dependencies, automated pr
branch: ensmallen-lib-updates-${{ steps.ensmallen-lib.outputs.release_tag }}