-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve outdated tutorials check #1021
Open
jooola
wants to merge
1
commit into
hetzneronline:master
Choose a base branch
from
jooola:stale
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only create an issue if the workflow is run from a schedule, since we only want to test the summary generation in pull requests. |
||
run: | | ||
gh issue create \ | ||
--title "Tutorials written over a year ago ($(date +'%B %Y'))" \ | ||
--body-file summary.md | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -eu | ||
|
||
# Print tutorials table header | ||
# print_header | ||
print_header() { | ||
cat <<EOF | ||
| Date | Path | Title | Author | | ||
| ------- | ------- | ------- | ------- | | ||
EOF | ||
} | ||
|
||
# Print tutorial table row | ||
# print_row <date> <slug> <title> <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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allows the workflow to run on pull request, so we can test changes.