Dev/nick #677
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
name: release-render-pipeline | |
on: | |
pull_request: | |
types: | |
- closed | |
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 | |
- 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 ' ') | |
file_list=$(echo "$raw_file_list" | sed 's/^/software\//') | |
echo "Files to monitor:" | |
echo "$file_list" | |
echo "file_list<<EOF" >> $GITHUB_OUTPUT | |
echo "$file_list" >> $GITHUB_OUTPUT | |
echo "EOF" >> $GITHUB_OUTPUT | |
- name: Copy Files to Release Folder | |
run: | | |
mkdir -p software/release # Ensure the release folder exists | |
echo "${{ steps.parse.outputs.file_list }}" | 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 | |
- name: List Files in Release Folder | |
run: | | |
echo "Files copied to the release folder:" | |
find software/release -type f | |
- name: Update Version in Config.py | |
run: | | |
# Get the list of changed (staged) files using git diff | |
changed_files=$(git diff --name-only) | |
new_files=$(git ls-files --others --exclude-standard) | |
all_changed_files=$(echo "$changed_files $new_files" | tr ' ' '\n') | |
echo "${{ steps.parse.outputs.file_list }}" | while read file; do | |
base_file=$(basename "$file") | |
if echo "$all_changed_files" | grep -q "$base_file"; then | |
if grep -q "$base_file" software/release/config.py; then | |
current_version=$(sed -n "s/^.*'$base_file': \([0-9]*\),.*$/\1/p" software/release/config.py) | |
new_version=$((current_version + 1)) | |
sed -i "s/^.*'$base_file': $current_version,.*$/'$base_file': $new_version,/g" software/release/config.py | |
echo "Updated $base_file version from $current_version to $new_version" | |
else | |
sed -i "/^version = {/a \ \ \ \ '$base_file': 1," software/release/config.py | |
echo "Added $base_file with version 1" | |
fi | |
else | |
echo "No change detected for $base_file" | |
fi | |
done | |
- 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" | |
- name: Set up Pull Request from main to original branch | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
# Ensure the latest changes from remote are fetched | |
git fetch origin | |
# Get the original branch from the pull request | |
original_branch="dev/nick" | |
# Check if the original branch exists | |
if git show-ref --verify --quiet "refs/remotes/origin/$original_branch"; then | |
# Create a pull request from main to the original branch | |
pr_url=$(gh pr create --base "$original_branch" --head "main" --title "Sync main with $original_branch" --body "Automated sync from main branch" --fill || echo "") | |
# Merge the pull request if created | |
if [[ -n "$pr_url" ]]; then | |
pr_number=$(echo "$pr_url" | grep -oP '\d+$') | |
gh pr merge "$pr_number" --merge --admin || echo "Failed to merge PR $pr_number" | |
else | |
echo "No new pull request was created." | |
fi | |
else | |
echo "Error: The branch '$original_branch' does not exist remotely." | |
fi |