diff --git a/.github/workflows/check-annual-update.yml b/.github/workflows/check-annual-update.yml deleted file mode 100644 index bbfa06cc7..000000000 --- a/.github/workflows/check-annual-update.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Annual review - -on: - schedule: - - cron: '0 0 1 * *' -# workflow_dispatch: - -jobs: - changed_files: - runs-on: ubuntu-latest - name: Create a new issue with tutorials that need their annual review - permissions: - issues: write - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set environment variables - run: | - echo "CURRENT_MONTH=$(date +'%Y-%m-%d' | cut -d'-' -f2)" >> $GITHUB_ENV - echo "CURRENT_MONTH_WRITTEN=$(date -d "$(date +'%Y-%m-%d' | cut -d'-' -f2)" "+%B")" >> $GITHUB_ENV - - - name: Find Markdown files and extract date, title and author - run: | - # Create summary file - echo "The tutorials below were written over a year ago.

" >> summary-authors.md - echo "All authors, please do the following:

" >> summary-authors.md - echo "| Path | Title | Author |" >> summary-authors.md - echo "| ------- | ------- | ------- |" >> summary-authors.md - - # Get all Markdown files - md_files=$(find ./tutorials -type f -name "*.en.md" | sort) - - touch orphaned - - # Run the commands below for each individual file - for file in $md_files; do - # Extract metadata from Markdown file - metadata=$(head -n 20 "$file" | awk '/^---$/{f=!f;next}f' | yq -o=json) - - # Extract month/path/title/author from the metadata - tutorial_month=$(echo "$metadata" | yq '.date' | cut -d '-' -f2) - path=$(echo "$metadata" | yq '.slug') - title=$(echo "$metadata" | yq '.title') - author=$(echo "$metadata" | yq '.author_link' | sed 's|https://github.com/|@|') - - # Compare CURRENT_MONTH with tutorial_month - if [ "$CURRENT_MONTH" == "$tutorial_month" ]; then - if [ "$author" == '@hetzneronline' ]; then author=Hetzner; fi - row="| [$path](https://github.com/hetzneronline/community-content/tree/master/tutorials/$path/01.en.md) | $title | $author |" - if [ -z "$author" ]; then - echo "$row" >> orphaned - else - echo "$row" >> summary-authors.md - fi - fi - done - cat orphaned >> summary-authors.md - cat summary-authors.md >> $GITHUB_STEP_SUMMARY - - - name: Create a new issue - run: | - gh issue create \ - --title "Tutorials written over a year ago ($CURRENT_MONTH_WRITTEN)" \ - --body-file summary-authors.md - env: - GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/outdated-tutorials.yml b/.github/workflows/outdated-tutorials.yml new file mode 100644 index 000000000..f84ca637a --- /dev/null +++ b/.github/workflows/outdated-tutorials.yml @@ -0,0 +1,41 @@ +name: Outdated Tutorials + +on: + schedule: + - cron: "0 0 1 * *" + push: + branches: [master] + paths: + - .github/workflows/outdated-tutorials.yml + - hack/outdated-tutorials-summary.sh + pull_request: + branches: [master] + paths: + - .github/workflows/outdated-tutorials.yml + - hack/outdated-tutorials-summary.sh + +jobs: + summary: + name: Summary + + runs-on: ubuntu-latest + + permissions: + issues: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Generate summary + run: | + hack/outdated-tutorials-summary.sh | tee summary.md $GITHUB_STEP_SUMMARY + + - name: Create issue + if: github.event_name == 'schedule' + run: | + gh issue create \ + --title "Tutorials written over a year ago ($(date +'%B %Y'))" \ + --body-file summary.md + env: + GH_TOKEN: ${{ github.token }} diff --git a/hack/outdated-tutorials-summary.sh b/hack/outdated-tutorials-summary.sh new file mode 100755 index 000000000..a2d6464b5 --- /dev/null +++ b/hack/outdated-tutorials-summary.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -eu + +# Print tutorials table header +# print_header +print_header() { + cat < <author> +print_row() { + echo "| $1 | [$2](https://github.com/hetzneronline/community-content/tree/master/tutorials/$2/01.en.md) | $3 | $4 |" +} + +# Create temporary files and add cleanup hook +rows="$(mktemp rows.XXXXXX.md)" +rows_orphaned="$(mktemp rows-orphaned.XXXXXX.md)" +trap 'rm -f "$rows" "$rows_orphaned"' EXIT + +# Get last year timestamp and month +last_year_timestamp=$(date +'%s' -d '1 year ago') +last_year_month=$(date +'%m' -d '1 year ago') + +# Run for each english tutorial file +for file in $(find ./tutorials -type f -name "*.en.md" | sort); do + + # Extract metadata + date=$(yq --front-matter extract '.date' "$file") + slug=$(yq --front-matter extract '.slug' "$file") + title=$(yq --front-matter extract '.title' "$file") + author=$(yq --front-matter extract '.author_link' "$file" | sed 's|https://github.com/|@|') + + # Get tutorial timestamp and month + date_timestamp=$(date +'%s' -d "$date") + date_month=$(date +'%m' -d "$date") + + # Check if the tutorial date is older that 1 year ago and on the same month + if [[ "$last_year_timestamp" -ge "$date_timestamp" && "$last_year_month" == "$date_month" ]]; then + + if [[ "$author" == '@hetzneronline' ]]; then + author=Hetzner + fi + + if [[ -z "$author" ]]; then + print_row "$date" "$slug" "$title" "$author" >>"$rows_orphaned" + else + print_row "$date" "$slug" "$title" "$author" >>"$rows" + fi + fi +done + +# Print summary header +cat <<EOF +The tutorials below were written over a year ago. + +All authors, please do the following: + +- Take a look at your tutorial and check if it still works. +- Comment on this issue if your tutorial needs an update or not. +- If your tutorial does need an update, please let us know if you plan to update the + tutorial yourself. If not, we might need to delete your tutorial. + +EOF + +# Print table and sort rows by date +print_header +sort "$rows" +sort "$rows_orphaned" + +# Print empty up to date table +cat <<EOF + +--- + +Up to date: + +EOF +print_header