Last active
January 22, 2024 05:32
-
-
Save micedreams/d2452ab96255da983e9527b361e46bc1 to your computer and use it in GitHub Desktop.
Workflow to turn any repository into a journal that automatically creates a new entry every day and archives the last entry into an archive folder..
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: Journal | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
create-file: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up Git repository | |
uses: actions/checkout@v2 | |
- name: Create a new archive folder. | |
run: mkdir -p "archive" | |
- name: Create a new template file. | |
run: | | |
if [[ ! -f "template.md" ]]; then | |
touch "template.md" | |
echo "# Template" >> "${DATE}.md" | |
fi | |
- name: Archive last entry. | |
run: | | |
DATE=$(DATE --DATE="-1 day" +"%d.%m.%Y") | |
if [[ -f "${DATE}.md" ]]; then | |
mv "${DATE}.md" "archive/" | |
fi | |
- name: Create a new entry | |
run: | | |
DATE=$(DATE +"%d.%m.%Y") | |
touch "${DATE}.md" | |
file_size=$(stat -c%s "${DATE}.md") | |
if [[ $file_size -eq 0 ]]; then | |
echo "###### ${DATE}" >> "${DATE}.md" | |
cat "template.md" >> "${DATE}.md" | |
fi | |
- name: Commit files | |
run: | | |
if [[ ! -z "$(git status --porcelain)" ]]; then | |
git config --local core.autocrlf false | |
git config --local user.email "${{ github.actor }}@users.noreply.github.com" | |
git config --local user.name "${{ github.actor }}" | |
git add . && git add --renormalize . | |
git pull origin ${{ github.head_ref }} --autostash --rebase -X ours | |
git commit --allow-empty -am "Add new entry." | |
NO_PAGER=1 git --no-pager diff HEAD^ | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@v0.6.0 | |
with: | |
branch: ${{ github.head_ref }} | |
github_token: ${{ secrets.TOKEN }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few suggestions for improvement:
shell: bash
wherever you have arun: …
line.if [[! -f "archive" ]]; then
->if [[ ! -f "archive" ]]; then
.mkdir -p 'folder'
.DATE
instead ofdate
) – reasoning? UNIX-based commands are lowercase, would be harder to differentiate betweendate
being a command from a variable.DATE="$(date --date='-1 day' +'%d.%m.%Y')"
--date='-1 day'
instead of--date="-1 day"
, but if you want to use$COUNT
somewhere and pass as a value, then you use--date="+$COUNT day"
.Otherwise, a very nice workflow and a good writeup! Keep it up 🎉