3. Update Package Data (if tests passed) #11
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
### Overwrite FrEDI data with past data | |
# on: | |
# workflow_run: | |
# workflows: ["Compile FrEDI Data"] | |
name: 3. Update Package Data (if tests passed) | |
on: | |
workflow_dispatch: | |
inputs: | |
passed_tests: | |
type: choice | |
description: Did data pass tests? | |
required: true | |
options: | |
- no | |
- yes | |
workflow_id: | |
type: string | |
description: Enter the run ID for the workflow from which to retrieve the main FrEDI Data | |
jobs: | |
# This workflow contains a single job called "build" | |
update_data: | |
runs-on: ubuntu-latest | |
name: Update Data | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Setup R | |
uses: r-lib/actions/setup-r@v2 | |
- name: Setup R package dependencies | |
uses: r-lib/actions/setup-r-dependencies@v2 | |
with: | |
cache: true | |
cache-version: 1 | |
packages: | | |
any::tidyverse | |
any::ggpubr | |
any::openxlsx | |
any::devtools | |
any::admisc | |
any::zoo | |
# - name: Send test status | |
# run: echo "${{ github.event.inputs.passed_tests }}" | |
- name: Send input status | |
run: | | |
echo "$${{ github.ref_name }} ${{ inputs.passed_tests }} ${{ inputs.workflow_id }}" | |
### Download tmp_sysdata.rda from 1. Compile Main FrEDI Data run | |
- name: Download all artifacts | |
id: download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
# github-token: ${{ GITHUB_PAT }} | |
run-id: ${{ inputs.workflow_id }} | |
path: ./data | |
- run: | | |
pwd | |
ls -R ./data/Data | |
# github.event.inputs.passed_tests == 'true' | |
# github.inputs.passed_tests == 'true' | |
# cp data/tmp_sysdata.rda data/sysdata.rda | |
# ${{ ( github.inputs.passed_tests == 'true' ) || ( github.inputs.passed_tests == 'yes' ) }} | |
- name: Update Data | |
if: | | |
${{ ( inputs.passed_tests == 'true' ) || | |
( inputs.passed_tests == 'yes' ) }} | |
run: | | |
rm ./data/sysdata.rda | |
cp ./data/Data/tmp_sysdata.rda ./data/sysdata.rda | |
rm ./data/Data/tmp_sysdata.rda | |
# github.event.inputs.passed_tests == 'true' | |
- name: Add SV Data to sysdata | |
if: | | |
${{ ( inputs.passed_tests == 'true' ) || | |
( inputs.passed_tests == 'yes' ) }} | |
run: | | |
Rscript -e ' | |
### Libraries | |
require(tidyverse) | |
require(devtools) | |
###### Set Paths ###### | |
### Project path | |
### Data output path and file name | |
projectDir <- "." | |
dataDir <- projectDir |> file.path("data") | |
svDir <- dataDir |> file.path("sv") | |
### Filenames | |
dataFile <- "sysdata.rda" | |
###### 0. Local Function ###### | |
projectDir |> devtools::load_all() | |
###### 1. Add SV Data to sysdata.rda ###### | |
tmpData <- projectDir |> update_sysdata( | |
dataPath = dataDir, | |
mainFile = dataFile, | |
sv = TRUE , | |
svPath = svDir, | |
svExt = "rda", | |
save = TRUE , | |
return = FALSE | |
) ### End update_sysdata | |
' | |
- name: Commit results | |
if: | | |
${{ ( inputs.passed_tests == 'true' ) || | |
( inputs.passed_tests == 'yes' ) }} | |
run: | | |
# Configure github | |
git config --local core.autocrlf false | |
git config --local user.email "${{ github.actor }}@users.noreply.github.com" | |
git config --local user.name "${{ github.actor }}" | |
# Navigate to the repository directory (optional, set the path below if needed) | |
# cd /path/to/your/repo | |
# Add data files | |
git add ./data/*.rd* | |
# Rebase files | |
git pull origin ${{ github.head_ref }} --autostash --rebase -X ours | |
# git commit -a -m "Updated sysdata and added SV data to sysdata" | |
# git push | |
# Check for staged changes | |
if git diff --cached --quiet; then | |
echo "No changes staged for commit." | |
else | |
echo "Some changes staged for commit." | |
# Commit the changes | |
commit_message="Auto-commit: Updated sysdata and added SV data to sysdata. Date: $(date '+%Y-%m-%d %H:%M:%S')" | |
git commit -m "$commit_message" | |
echo "Changes committed with message: '$commit_message'." | |
git push | |
fi |