Skip to content

Commit f8d19fb

Browse files
committed
Update build_packages_info.yml and README.md to improve GitHub repo handling and documentation
1 parent 552e7d1 commit f8d19fb

2 files changed

Lines changed: 73 additions & 61 deletions

File tree

.github/workflows/build_packages_info.yml

Lines changed: 71 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Start with a list of packages in packages.csv, and get external data about them (e.g. last commit date) to generate an HTML page with the package information. This workflow is triggered manually from the Actions tab.
22
# Olly Butters
3-
# 1/5/26
3+
# 15/5/26
44
name: Package list
55

66
# Controls when the workflow will run
@@ -29,6 +29,7 @@ jobs:
2929
# Create new output file
3030
echo "Name,Description,CRAN link,CRAN version, CRAN license,Last commit,GitHub version,GitHub license,Github owner,Status" > output.csv
3131
32+
# Read the data in from package_list.csv. The name and gh_link fields are required.
3233
while IFS="," read -r name description gh_link cran_link status
3334
do
3435
echo "-----------------------------------"
@@ -46,67 +47,80 @@ jobs:
4647
gh_repo_name=$(echo $gh_link | awk -F/ '{print $NF}')
4748
echo $gh_repo_name
4849
49-
# clone the repo
50-
git clone $gh_link
51-
cd $gh_repo_name
52-
53-
# Last commit date of repo
54-
gh_last_commit=$(git log -1 --format=%cs)
55-
echo "last commit: $gh_last_commit"
56-
57-
# Last release
58-
if [ $(git rev-list --tags --max-count=1) ]; then
59-
gh_last_release=$(git describe --tags $(git rev-list --tags --max-count=1))
60-
else
50+
# clone the GitHub repo and process it
51+
if [ -z "${gh_link}" ]; then
52+
echo "No GitHub link provided, skipping GitHub info for this package."
53+
gh_last_commit=""
6154
gh_last_release=""
62-
fi
63-
64-
echo "last GitHub release: $gh_last_release"
65-
66-
if [ -f "NAMESPACE" ]; then
67-
echo "NAMESPACE file found"
68-
gh_functions=$(sed -n "s/^export(\(.*\))$/\1/p" NAMESPACE | tr '\n' ',')
69-
echo "GitHub functions: $gh_functions"
70-
if [ -n "${gh_functions}" ]; then
71-
echo "${name}: ${gh_functions}" >> ../functions.txt
55+
gh_license=""
56+
gh_functions=""
57+
gh_owner=""
58+
gh_code_of_conduct=""
59+
else
60+
echo "Cloning GitHub repo: $gh_link"
61+
git clone $gh_link
62+
cd $gh_repo_name
63+
64+
# Last commit date of repo
65+
gh_last_commit=$(git log -1 --format=%cs)
66+
echo "last commit: $gh_last_commit"
67+
68+
# Last release
69+
if [ $(git rev-list --tags --max-count=1) ]; then
70+
gh_last_release=$(git describe --tags $(git rev-list --tags --max-count=1))
7271
else
73-
echo $name >> ../functions.txt
72+
gh_last_release=""
7473
fi
75-
fi
76-
77-
# Use the GitHub API to pull in info about the repoisitory
78-
echo "\nGitHub API information"
79-
gh repo view --json codeOfConduct,description,homepageUrl,licenseInfo,owner,parent,updatedAt > gh_repo_info.json
80-
echo "API response:"
81-
cat gh_repo_info.json
82-
83-
# Get the license as it appears in GitHub
84-
gh_license=$(cat gh_repo_info.json | jq '.licenseInfo.nickname')
85-
if [ -z "${gh_license}" ] || [ "${gh_license}" = '""' ]; then
86-
gh_license=$(cat gh_repo_info.json | jq '.licenseInfo.name')
87-
fi
88-
89-
# If the license is "Other", check for a LICENSE.md file and see if it contains actual license
90-
if [ "${gh_license}" = '"Other"' ]; then
91-
if [ -f "LICENSE.md" ]; then
92-
echo "License file found: LICENSE.md"
93-
if $(grep -q "MIT License" LICENSE.md); then
94-
gh_license="MIT License"
74+
75+
echo "last GitHub release: $gh_last_release"
76+
77+
# If there is a NAMES file then parse it to get the functino list and save the output
78+
if [ -f "NAMESPACE" ]; then
79+
echo "NAMESPACE file found"
80+
gh_functions=$(sed -n "s/^export(\(.*\))$/\1/p" NAMESPACE | tr '\n' ',')
81+
echo "GitHub functions: $gh_functions"
82+
if [ -n "${gh_functions}" ]; then
83+
echo "${name}: ${gh_functions}" >> ../functions.txt
84+
else
85+
echo $name >> ../functions.txt
9586
fi
9687
fi
88+
89+
# Use the GitHub API to pull in info about the repoisitory
90+
echo "\nGitHub API information"
91+
gh repo view --json codeOfConduct,description,homepageUrl,licenseInfo,owner,parent,updatedAt > gh_repo_info.json
92+
echo "API response:"
93+
cat gh_repo_info.json
94+
95+
# Get the license as it appears in GitHub
96+
gh_license=$(cat gh_repo_info.json | jq '.licenseInfo.nickname')
97+
if [ -z "${gh_license}" ] || [ "${gh_license}" = '""' ]; then
98+
gh_license=$(cat gh_repo_info.json | jq '.licenseInfo.name')
99+
fi
100+
101+
# If the license is "Other", check for a LICENSE.md file and see if it contains actual license
102+
if [ "${gh_license}" = '"Other"' ]; then
103+
if [ -f "LICENSE.md" ]; then
104+
echo "License file found: LICENSE.md"
105+
if $(grep -q "MIT License" LICENSE.md); then
106+
gh_license="MIT License"
107+
fi
108+
fi
109+
fi
110+
111+
echo "GitHub license: $gh_license"
112+
113+
gh_owner=$(cat gh_repo_info.json | jq '.owner.login')
114+
echo "GitHub owner: $gh_owner"
115+
116+
gh_code_of_conduct=$(cat gh_repo_info.json | jq '.codeOfConduct.name')
117+
echo "GitHub code of conduct: $gh_code_of_conduct"
118+
119+
# Tidy up
120+
cd ..
121+
rm -rf $gh_repo_name
97122
fi
98123

99-
echo "GitHub license: $gh_license"
100-
101-
gh_owner=$(cat gh_repo_info.json | jq '.owner.login')
102-
echo "GitHub owner: $gh_owner"
103-
104-
gh_code_of_conduct=$(cat gh_repo_info.json | jq '.codeOfConduct.name')
105-
echo "GitHub code of conduct: $gh_code_of_conduct"
106-
107-
# Tidy up
108-
cd ..
109-
rm -rf $gh_repo_name
110124

111125
##### CRAN info
112126
echo "CRAN information"
@@ -119,11 +133,6 @@ jobs:
119133
CRAN_package_name=$(echo $cran_link | awk -F= '{print $NF}')
120134
echo "CRAN package name: $CRAN_package_name"
121135

122-
# Get the version number from CRAN
123-
# This is overkill really, it takes ages to install all the R dependencies. Could just parse the CRAN DESCRIPTION file.
124-
#version=$(Rscript --vanilla -e 'print(subset(tools::CRAN_package_db(), Package == "dsBase")[["Version"]], row.names=FALSE)')
125-
#echo "version: $version"
126-
127136
cran_description_file_link="https://cran.r-project.org/web/packages/${CRAN_package_name}/DESCRIPTION"
128137
wget --content-on-error $cran_description_file_link
129138

@@ -150,12 +159,13 @@ jobs:
150159

151160
done < <(tail -n +2 package_list.csv)
152161

162+
# copy files to a new directory for deployment
153163
mkdir gh-pages
154164
cp output.csv gh-pages/
155165
cp functions.txt gh-pages/
156166

167+
# print the output files to the console for debugging
157168
cat output.csv
158-
159169
cat functions.txt
160170

161171
env:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# packages
22
Automatically make a list of the DataSHIELD packages using info from CRAN and GitHub.
3+
4+
If there are any packages missing, please add them to the list in `/packages_list.csv` via a pull request, or submit an issue.

0 commit comments

Comments
 (0)