-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (69 loc) · 3.47 KB
/
drat--update-readme.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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"