Skip to content

Monthly Release

Monthly Release #43

name: Monthly Release
on:
workflow_dispatch:
schedule:
- cron: '0 2 1 * *'
jobs:
monthly-release:
runs-on: ubuntu-latest
continue-on-error: true
env:
RENV_PATHS_ROOT: ~/.local/share/renv
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install rsvg-convert
run: sudo apt-get update && sudo apt-get install -y librsvg2-bin
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
- name: Setup R
uses: r-lib/actions/setup-r@v2
# - name: Setup renv
# uses: r-lib/actions/setup-renv@v2
- name: Restore R package cache
uses: actions/cache@v3
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-
- name: Install R dependencies
run: |
if (!requireNamespace("remotes", quietly = TRUE)) {install.packages("remotes", dependencies = TRUE, quiet = TRUE, verbose = FALSE)}
remotes::install_deps(dependencies = TRUE)
if (!requireNamespace("renv", quietly = TRUE)) install.packages("renv", dependencies = TRUE, quiet = TRUE, verbose = FALSE)
renv::restore()
if (!requireNamespace("fs", quietly = TRUE)) install.packages("fs", dependencies = TRUE, quiet = TRUE, verbose = FALSE)
if (!requireNamespace("quarto", quietly = TRUE)) install.packages("quarto", dependencies = TRUE, quiet = TRUE, verbose = FALSE)
if (!requireNamespace("xfun", quietly = TRUE)) {install.packages("xfun", dependencies = TRUE, quiet = TRUE, verbose = FALSE)}
if (!requireNamespace("readxl", quietly = TRUE)) {install.packages("readxl", dependencies = TRUE, quiet = TRUE, verbose = FALSE)}
if (!requireNamespace("tinytex", quietly = TRUE)) {install.packages("tinytex, dependencies = TRUE, quiet = TRUE, verbose = FALSE")}
if (!tinytex::is_tinytex()) {tinytex::install_tinytex()}
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
- name: "epub word TR"
shell: Rscript {0}
run: |
source("./R/render_epub_word_TR.R")
continue-on-error: true
- name: "Install epubcheck"
run: sudo apt-get update && sudo apt-get install -y epubcheck
- name: "Check epub TR"
run: epubcheck ./_epub_word_TR/Patoloji-Atlasi.epub
continue-on-error: true
- name: "pdf TR"
shell: Rscript {0}
run: |
source("./R/render_pdf_TR.R")
continue-on-error: true
- name: "epub word EN"
shell: Rscript {0}
run: |
source("./R/render_epub_word_EN.R")
continue-on-error: true
- name: "Check epub EN"
run: epubcheck ./_epub_word_EN/HistoPatology-Atlas.epub
continue-on-error: true
- name: "pdf EN"
shell: Rscript {0}
run: |
source("./R/render_pdf_EN.R")
continue-on-error: true
- name: Get current date
id: current_date
run: echo "DATE=$(date +'%Y-%m')" >> $GITHUB_ENV
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install -y jq curl
- name: Prepare and Upload Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG_NAME: ${{ env.DATE }}
# TAG_NAME: ${{ github.ref_name }}
run: |
# Define files to check
FILES=(
"./_epub_word_TR/Patoloji-Atlasi.epub"
"./_epub_word_TR/Patoloji-Atlasi.docx"
"./_pdf_TR/Patoloji-Atlasi.pdf"
"./_epub_word_EN/HistoPatology-Atlas.epub"
"./_epub_word_EN/HistoPatology-Atlas.docx"
"./_pdf_EN/HistoPathology-Atlas.pdf"
)
# Create Release
RELEASE_DATA=$(curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${GITHUB_REPOSITORY}/releases \
-d '{
"tag_name": "'$TAG_NAME'",
"name": "Release for '"$TAG_NAME"'",
"body": "Epub, Word & Pdf generated for the month of '"$TAG_NAME"'",
"draft": false,
"prerelease": false
}')
UPLOAD_URL=$(echo $RELEASE_DATA | jq -r .upload_url | sed -e "s/{?name,label}//")
# Upload each existing file
for FILE_PATH in "${FILES[@]}"; do
if [ -f "$FILE_PATH" ]; then
FILE_NAME=$(basename $FILE_PATH)
echo "Uploading $FILE_NAME..."
curl -s -X POST -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: application/octet-stream" \
-H "Accept: application/vnd.github+json" \
--data-binary @"$FILE_PATH" \
"${UPLOAD_URL}?name=$(basename $FILE_PATH)"
else
echo "$FILE_PATH does not exist, skipping."
fi
done
# - name: Prepare files list
# id: prep_files
# run: |
# FILES=""
# for file in ./_epub_word_TR/Patoloji-Atlasi.epub \
# ./_epub_word_TR/Patoloji-Atlasi.docx \
# ./_pdf_TR/Patoloji-Atlasi.pdf \
# ./_epub_word_EN/HistoPatology-Atlas.epub \
# ./_epub_word_EN/HistoPatology-Atlas.docx \
# ./_pdf_EN/HistoPathology-Atlas.pdf; do
# if [ -f "$file" ]; then
# FILES="$FILES$file\n"
# fi
# done
# # Use environment file to set the variable
# echo "FILES_LIST<<EOF" >> $GITHUB_ENV
# echo -e $FILES >> $GITHUB_ENV
# echo "EOF" >> $GITHUB_ENV
# - name: Release
# uses: softprops/action-gh-release@v1
# env:
# FILES: ${{ env.FILES_LIST }}
# with:
# tag_name: release-${{ env.DATE }}
# release_name: Release for ${{ env.DATE }}
# draft: false
# prerelease: false
# body: |
# Epub, Word & Pdf generated for the month of ${{ env.DATE }}
# files: |
# ${{ env.FILES }}
# - name: Release
# uses: softprops/action-gh-release@v1
# with:
# tag_name: release-${{ env.DATE }}
# release_name: Release for ${{ env.DATE }}
# draft: false
# prerelease: false
# body: |
# Epub, Word & Pdf generated for the month of ${{ env.DATE }}
# files: |
# ./_epub_word_TR/Patoloji-Atlasi.epub
# ./_epub_word_TR/Patoloji-Atlasi.docx
# ./_pdf_TR/Patoloji-Atlasi.pdf
# ./_epub_word_EN/HistoPatology-Atlas.epub
# ./_epub_word_EN/HistoPatology-Atlas.docx
# ./_pdf_EN/HistoPathology-Atlas.pdf