mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
Fixes the following error when generating the upcoming changes status
report
on a weekly basis in GitHub actions:
```
/__w/discourse/discourse/lib/upcoming_changes/status_report.rb:56:in 'UpcomingChanges::StatusReport::Git#capture': git show 45535887f1231b40f8a21b8c154e58cef8670063:plugins/discourse-workflows/config/settings.yml failed: fatal: path 'plugins/discourse-workflows/config/settings.yml' exists on disk, but not in '45535887f1' (RuntimeError)
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:47:in 'UpcomingChanges::StatusReport::Git#show_file'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:227:in 'UpcomingChanges::StatusReport::GitHistory#statuses_at'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:215:in 'block in UpcomingChanges::StatusReport::GitHistory#add_history_for_settings_file'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:214:in 'Array#reverse_each'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:214:in 'UpcomingChanges::StatusReport::GitHistory#add_history_for_settings_file'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:205:in 'block in UpcomingChanges::StatusReport::GitHistory#by_change'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:202:in 'Hash#each'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:202:in 'Enumerable#each_with_object'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:202:in 'UpcomingChanges::StatusReport::GitHistory#by_change'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:422:in 'UpcomingChanges::StatusReport#history_by_change'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:363:in 'block in UpcomingChanges::StatusReport#report'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:362:in 'Hash#each'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:362:in 'Enumerable#map'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:362:in 'UpcomingChanges::StatusReport#report'
from /__w/discourse/discourse/lib/upcoming_changes/status_report.rb:499:in 'UpcomingChanges::StatusReport::CLI.run'
from /__w/discourse/discourse/script/upcoming_changes_status_report:9:in '<main>'
```
This happened because we were trying to run `git sho` on a file that was
reverted in a commit. Now, we check whether the file exists for the
specific commit hash before running git show, and continue with the
next valid commit for the file.
35 lines
1.2 KiB
Bash
Executable file
Vendored
35 lines
1.2 KiB
Bash
Executable file
Vendored
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
stale_after_days="${STALE_AFTER_DAYS:-14}"
|
|
dry_run="${DRY_RUN:-true}"
|
|
|
|
bin/rails runner script/upcoming_changes_status_report -- \
|
|
--stale-after-days "${stale_after_days}" \
|
|
--pretty > /tmp/upcoming_changes_status_report.json
|
|
|
|
cat /tmp/upcoming_changes_status_report.json
|
|
|
|
eligible_count="$(
|
|
ruby -rjson -e 'records = JSON.parse(File.read(ARGV.fetch(0))); puts records.count { |record| record["eligible"] }' /tmp/upcoming_changes_status_report.json
|
|
)"
|
|
|
|
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
|
echo "eligible_count=${eligible_count}" >> "${GITHUB_OUTPUT}"
|
|
fi
|
|
|
|
if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then
|
|
{
|
|
echo "### Upcoming change status report"
|
|
echo
|
|
echo "- Dry run: \`${dry_run}\`"
|
|
echo "- Stale after days: \`${stale_after_days}\`"
|
|
echo "- Eligible changes: \`${eligible_count}\`"
|
|
echo
|
|
ruby -rjson -e '
|
|
JSON.parse(File.read(ARGV.fetch(0))).select { |record| record["eligible"] }.each do |record|
|
|
puts "- `#{record["name"]}`: `#{record["current_status"]}` -> `#{record["next_status"]}` in `#{record["settings_path"]}`; last changed #{record["days_since_status_change"]} days ago"
|
|
end
|
|
' /tmp/upcoming_changes_status_report.json
|
|
} >> "${GITHUB_STEP_SUMMARY}"
|
|
fi
|