Automated deploy from hyperSpec #578
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
on: push | |
name: drat-readme | |
jobs: | |
drat-readme: | |
name: Update README | |
runs-on: ubuntu-latest | |
env: | |
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: '0' # Allows correct dates in git history | |
- uses: r-lib/actions/setup-r@v2 | |
- name: update repo indices # Needed if tar balls removed manually | |
run: | | |
install.packages("drat") | |
drat::updateRepo(".") | |
shell: Rscript {0} | |
- name: Drat -- update README.md | |
if: success() | |
run: | | |
# Grab the portion of the file we want to re-use: | |
# from the beginning to the "last_line" that should be reused | |
last_line='<!-- list of packages: start | DO NOT REMOVE THIS LINE -->' | |
awk '/^# /, /^'"$last_line"'/' README.md > README.tmp | |
# ================================================================= | |
# Insert the list of packages (current versions) | |
echo "" >> README.tmp # add blank line | |
echo "Packages currently residing here:" >> README.tmp | |
echo "" >> README.tmp # add blank line | |
echo "Package | Version | Updated on " >> README.tmp | |
echo "---------------- | ------------ | ------------- " >> README.tmp | |
git ls-files -z '*.tar.gz' |\ | |
xargs -0 -I {} -- git log -1 --format="%as {}" {} |\ | |
grep \.tar\.gz$ |\ | |
grep '(Archive|SKELETON)' -vE |\ | |
sed 's/src\/contrib\///g' |\ | |
sed 's/_|.tar.gz/ /g' -E |\ | |
awk '{printf "%-16s | %-12s | %s\n", $2, $3, $1}' |\ | |
sort -t$'|' -k1i,1 -k2Vr,2 >> README.tmp | |
echo "" >> README.tmp # add blank line | |
# ================================================================= | |
# Insert the list of packages (old versions) | |
# Do if any archived .tar.gz file exists | |
if [[ -n $(find "src/contrib" -type f | grep 'Archive/.*\.tar.gz$') ]] | |
then | |
echo "Previous (archived) versions of the packages residing here: " >> README.tmp | |
echo "" >> README.tmp # add blank line | |
echo "Package | Version | Updated on " >> README.tmp | |
echo "---------------- | ------------ | ------------- " >> README.tmp | |
git ls-files -z '*Archive/*.tar.gz' |\ | |
xargs -0 -I {} -- git log -1 --format="%as {}" {} |\ | |
sed 's/src\/contrib\/Archive\/.*\///g' |\ | |
sed 's/(_|.tar.gz)/ /g' -E |\ | |
awk '{printf "%-16s | %-12s | %s\n", $2, $3, $1}' |\ | |
sort -t$'|' -k1i,1 -k2Vr,2 >> README.tmp | |
echo "" >> README.tmp # add blank line | |
fi | |
# Add timestamp | |
echo "<p align=\"right\"> $(date +"%Y-%m-%d %T %Z") </p>" >> README.tmp | |
# Create a new version of README.md | |
mv README.tmp README.md | |
- name: Commit and push | |
if: success() | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git commit README.md -m "Update README" || echo "Nothing to commit" | |
git push origin || echo "Nothing to commit" |