Skip to content

Commit

Permalink
adding automatic update of issues
Browse files Browse the repository at this point in the history
  • Loading branch information
joergi committed Aug 4, 2023
1 parent f8756d7 commit 91eb444
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/update-to-newest-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Update latest issues

on:
schedule:
- cron: '0 12 * * *' # every day at noon
workflow_dispatch: {}

jobs:
update-latest-issues:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.3
- name: update issues
id: updateIssues
run: bash ./script-for-using-latest-version.sh
- uses: pCYSl5EDgo/cat@master
id: read_recent
with:
path: ./issues.txt
- run: |
echo "ISSUE_NUMBER=${{ steps.read_recent.outputs.text }}" >> $GITHUB_ENV
- name: config git
run: |
git config --local user.email "1439809+joergi@users.noreply.github.com"
git config --local user.name "Joergi via GitHub Actions"
- name: Create Pull Request
id: createAutoPR
uses: peter-evans/create-pull-request@v5
with:
title: new Issue ${{ env.ISSUE_NUMBER }} - Automated PR
commit-message: new Issue ${{ env.ISSUE_NUMBER }} - Automated PR
token: ${{ secrets.MY_GITHUB_TOKEN }}
body: Automated pull request for issue ${{ env.ISSUE_NUMBER }} created by GitHub Actions
branch: automated_PR_for_update_issues
branch-suffix: timestamp
base: main
delete-branch: true
labels: "automerge"
- name: Auto approve
id: autoApprove
if: steps.createAutoPR.outputs.pull-request-operation == 'created'
uses: juliangruber/approve-pull-request-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.createAutoPR.outputs.pull-request-number }}
- name: Enable Pull Request Automerge
if: steps.createAutoPR.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.MY_GITHUB_TOKEN }}
pull-request-number: ${{ steps.createAutoPR.outputs.pull-request-number }}
27 changes: 27 additions & 0 deletions script-for-using-latest-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
set -o errexit
#set -o pipefail
set -o nounset
IFS=$'\n\t'

# ------------------------------------------------------------------
# based on the script Kenichi Nagai https://github.com/keni-n/
# https://github.com/joergi/MagPiDownloader/blob/main/linux_mac/magpi-issue-downloader-latest.sh
# ------------------------------------------------------------------

# VERSION=0.1
# you don't need to run this script
# this is running automatically on Github each day to update the latest issues

TARGET_URL="https://helloworldraspberrypi.com/"
BASEDIR=$(dirname "$0")

#printf -v page_url "$TARGET_URL/issues"
page_url=$(printf '%s\n' "$TARGET_URL/issues")

latest_issue=$(curl -sf "$page_url" | grep "Get PDF" | head -n 1 | sed 's/^.*issues\///' | sed 's/\/pdf.*$//')
echo "Latest Issue is " "$latest_issue"

file="$BASEDIR/regular-issues.txt";
echo $file
echo "$latest_issue" >"$file"

0 comments on commit 91eb444

Please sign in to comment.