-
Notifications
You must be signed in to change notification settings - Fork 2
126 lines (106 loc) · 4.38 KB
/
release-render-pipeline.yml
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: release-render-pipeline
on:
push:
branches:
- main
jobs:
release-render:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ssh-key: ${{ secrets.RENDER_KEY }}
- name: Set up SSH for Git
run: |
mkdir -p ~/.ssh
echo "${{ secrets.RENDER_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
# --- Step 1: Parse and Copy Files to Release Folder ---
- name: Parse File List from release/README.qmd
id: parse
run: |
# Extract the table section and parse the file paths
raw_file_list=$(awk '/\| name/ {f=1; next} /\|----/ {next} f && /\|/ {print $2}' software/release/README.qmd | tr -d ' ')
# Add the software/ prefix to each file path
echo "$raw_file_list" | sed 's/^/software\//' > file_list.txt
# Debugging output
echo "Files to monitor:"
cat file_list.txt
- name: Copy Files to Release Folder
run: |
mkdir -p software/release # Ensure the release folder exists
while read file; do
# Skip the config.py file
if [[ "$(basename $file)" == "config.py" ]]; then
echo "Skipping config.py"
continue
fi
# Copy the file, overwriting if it already exists
cp "$file" software/release/ # Overwrite files directly to the root of the release folder
done < file_list.txt
- name: List Files in Release Folder
run: |
echo "Files copied to the release folder:"
find software/release -type f
# --- Step 2: Update Version in Config.py ---
- name: Update Version in Config.py
run: |
# Get the list of changed (staged) files using git diff
changed_files=$(git diff --name-only)
# Get the list of untracked files (new files that haven't been added yet)
new_files=$(git ls-files --others --exclude-standard)
# Combine the changed and new files
all_changed_files=$(echo "$changed_files $new_files" | tr ' ' '\n')
# Process each file in file_list.txt
while read file; do
# Extract the base file name from the full path
base_file=$(basename "$file")
# Check if the file has been modified (either staged or new file)
if echo "$all_changed_files" | grep -q "$base_file"; then
# Use Python to update the version
python3 - <<'EOF'
import ast
config_path = 'software/release/config.py'
with open(config_path, 'r') as f:
version = ast.literal_eval(f.read().strip().split('= ', 1)[1])
if '$base_file' in version:
version['$base_file'] += 1
print(f"Updated $base_file version to {version['$base_file']}")
else:
version['$base_file'] = 1
print(f"Added $base_file with version 1")
with open(config_path, 'w') as f:
f.write(f"version = {repr(version)}")
EOF
else
echo "No change detected for $base_file"
fi
done < file_list.txt
# --- Step 3: Render README.qmd to Markdown ---
- name: Set up R
uses: r-lib/actions/setup-r@v2
- name: Install Required R Packages
run: |
Rscript -e 'if (!requireNamespace("rmarkdown", quietly = TRUE)) install.packages("rmarkdown", repos = "https://cloud.r-project.org/")'
Rscript -e 'if (!requireNamespace("knitr", quietly = TRUE)) install.packages("knitr", repos = "https://cloud.r-project.org/")'
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
- name: Find and Render README.qmd Files
run: |
find . -name "README.qmd" | while read qmd_file; do
quarto render "$qmd_file" --to gfm
done
# --- Step 4: Commit and Push All Changes Once ---
- name: Commit and Push All Changes
run: |
# Configure Git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Check if there are changes to commit (release folder or rendered README files)
git diff --exit-code || (git add software/release/ && git add . && git commit -m "Release and Render")
# Push the changes if there were any
git push origin main || echo "No changes to push"