From f6fa301b1c12feb0b74e079616969b026607f12e Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Mon, 29 Jan 2024 14:24:57 +0100 Subject: [PATCH 1/3] Implement GTN News posting via Google Form --- .github/workflows/google-form.rb | 53 ++++++++++++++ bin/google-form-news.rb | 71 +++++++++++++++++++ bin/schema-news.yaml | 7 ++ faqs/gtn/gtn_news_create_post.md | 6 +- ...ied-gtn-news-submission-via-google-form.md | 24 +++++++ 5 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/google-form.rb create mode 100755 bin/google-form-news.rb create mode 100644 news/_posts/2024-01-29-simplified-gtn-news-submission-via-google-form.md diff --git a/.github/workflows/google-form.rb b/.github/workflows/google-form.rb new file mode 100644 index 00000000000000..bb5d7d27d7c829 --- /dev/null +++ b/.github/workflows/google-form.rb @@ -0,0 +1,53 @@ +name: "[Cron] Update news from Google Form" +on: + workflow_dispatch: + schedule: + - cron: '21 10 * * *' +jobs: + runner-job: + runs-on: ubuntu-latest + # Only run on main repo on and PRs that match the main repo. + if: | + github.repository == 'galaxyproject/training-material' && + (github.event_name != 'pull_request' || + github.event.pull_request.head.repo.full_name == github.repository) + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + + # BEGIN Dependencies + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.0" + - uses: actions/cache@v2 + with: + path: | + vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Install dependencies + run: | + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + bundle pristine ffi + # END Dependencies + + - name: Update Shortlinks + id: generate + run: | + ruby bin/google-form-news.rb >> $GITHUB_OUTPUT + + - name: Create Pull Request + # If it's not a Pull Request then commit any changes as a new PR. + if: | + github.event_name != 'pull_request' && + steps.generate.outputs.new_ids != '' + uses: peter-evans/create-pull-request@v3 + with: + title: Import news posts from Google Form + branch-suffix: timestamp + commit-message: New News Post! + add-paths: news/_posts/ diff --git a/bin/google-form-news.rb b/bin/google-form-news.rb new file mode 100755 index 00000000000000..f8542302b0a2ef --- /dev/null +++ b/bin/google-form-news.rb @@ -0,0 +1,71 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'yaml' +require 'net/http' +require 'csv' +require 'date' + +# Fetch data from a google sheet +url = 'https://docs.google.com/spreadsheets/d/1KJsQpZsUfaZh-a8jLx0gNymaQxvSNForrekEgIzF3Eo/export?format=tsv' +data = `curl -sL "#{url}"` + +contributions_keys = %w[Authorship Editing Testing Infrastructure Translation Funding] + +data = CSV.parse(data, col_sep: "\t", headers: true, quote_char: '|') + +data.each do |row| + # Parse + # 29/01/2024 14:04:47 + post_date = DateTime.strptime(row['Timestamp'], '%d/%m/%Y %H:%M:%S') + filename = "news/_posts/#{post_date.strftime('%Y-%m-%d')}-#{row['Title'].downcase.gsub(/[^a-z0-9\s]/i, '').gsub( + /\s+/, '-' + )}.md" + + # Skip some testing posts + if (row['Title'] == 'TESTING') || (row['Title'] == "Wendi's Dog is the Best") + puts "Skipping #{filename} as it is a test post" + next + end + + # Don't overwrite existing posts + if File.exist?(filename) + puts "Skipping #{filename} as it already exists" + next + end + + puts "Creating #{filename}" + + post_metadata = { + 'title' => row['Title'], + 'layout' => 'news', + 'tags' => row['Tags'].split(',').map(&:strip), + 'from_google_form' => true, + 'contributions' => {} + } + + contributions_keys.each do |key| + post_metadata['contributions'][key.downcase] = row[key].split(',').map(&:strip) if row[key] + end + + if row['Optional Cover Image'] + post_metadata['cover_image'] = row['Optional Cover Image'] + post_metadata['cover_image_alt'] = row['Cover Image Alternative Text'] + end + + if row['Link to a specific tutorial you wish to push people to view'] + post_metadata['tutorial'] = row['Link to a specific tutorial you wish to push people to view'] + end + + if row['Link for a non-tutorial thing you want to push people to view'] + post_metadata['link'] = row['Link for a non-tutorial thing you want to push people to view'] + end + + # Serialise to a file + + File.open(filename, 'w') do |file| + file.puts YAML.dump(post_metadata) + file.puts "---\n" + file.puts row['Blog Post'].gsub(/ /, "\n\n") + end +end diff --git a/bin/schema-news.yaml b/bin/schema-news.yaml index 7159e3de058af4..b5b422b6db049c 100644 --- a/bin/schema-news.yaml +++ b/bin/schema-news.yaml @@ -173,3 +173,10 @@ mapping: enum: - true - false + from_google_form: + type: bool + description: | + A boolean tracking in an automated way if this news post was generated via the GTN's News Google Form. Please do not add this manually. + enum: + - true + - false diff --git a/faqs/gtn/gtn_news_create_post.md b/faqs/gtn/gtn_news_create_post.md index 2bde104b0af996..e44c1ad3464db8 100644 --- a/faqs/gtn/gtn_news_create_post.md +++ b/faqs/gtn/gtn_news_create_post.md @@ -10,7 +10,11 @@ If you have created a new tutorial, running an event, published a paper around t News items will show up on the [GTN homepage]({% link index.md %}) and in the [GTN news feed]({% link news.md %}). -**Creating the news post** +**Creating the news post: The Easy Way** + +[Fill out this Google Form](https://forms.gle/6SRAVcppzieef7Zz9). Every day our bot will import the news posts submitted via this Google Form, and we will process them, perhaps requesting small changes, so we recommend that you have a GitHub account already. + +**For Advanced Users** Have a look at the existing news items in the [`news/_posts/` folder](https://github.com/galaxyproject/training-material/tree/main/news/_posts) of the GTN repository for some examples. diff --git a/news/_posts/2024-01-29-simplified-gtn-news-submission-via-google-form.md b/news/_posts/2024-01-29-simplified-gtn-news-submission-via-google-form.md new file mode 100644 index 00000000000000..8e2165b3f028b5 --- /dev/null +++ b/news/_posts/2024-01-29-simplified-gtn-news-submission-via-google-form.md @@ -0,0 +1,24 @@ +--- +title: Simplified GTN News submission via Google Form +layout: news +tags: +- gtn infrastructure +- new feature +- automation +from_google_form: true +contributions: + authorship: + - hexylena + testing: + - nomadscientist + infrastructure: + - hexylena +link: https://forms.gle/TqGTr6y46wrJDri7A +--- +Based on user feedback of the difficulties of the GTN news submission process we have significantly simplified and removed the need for manually editing a YAML file by providing a quick and easy [Google Form](https://forms.gle/TqGTr6y46wrJDri7A) + +Any news submitted via this form will be reviewed by the GTN maintainers, and, when linting is passing, merged. + +So if you have some cool training news you want to share, then please let us know! + +*Fun Fact*: This news post was prepared in the new Google Form. From 10a66bec79e0ca9489a81c891cdd7b377857fc1f Mon Sep 17 00:00:00 2001 From: Helena Date: Mon, 29 Jan 2024 14:37:16 +0100 Subject: [PATCH 2/3] Update bin/google-form-news.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- bin/google-form-news.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/google-form-news.rb b/bin/google-form-news.rb index f8542302b0a2ef..2a5e3559d35c3d 100755 --- a/bin/google-form-news.rb +++ b/bin/google-form-news.rb @@ -66,6 +66,6 @@ File.open(filename, 'w') do |file| file.puts YAML.dump(post_metadata) file.puts "---\n" - file.puts row['Blog Post'].gsub(/ /, "\n\n") + file.puts row['Blog Post'].gsub(" ", "\n\n") end end From b4167bad231e6fef309b78732204cc1cff4b216c Mon Sep 17 00:00:00 2001 From: Helena Date: Mon, 29 Jan 2024 14:43:37 +0100 Subject: [PATCH 3/3] Update bin/google-form-news.rb Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- bin/google-form-news.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/google-form-news.rb b/bin/google-form-news.rb index 2a5e3559d35c3d..f1c6ec0fbc5d48 100755 --- a/bin/google-form-news.rb +++ b/bin/google-form-news.rb @@ -66,6 +66,6 @@ File.open(filename, 'w') do |file| file.puts YAML.dump(post_metadata) file.puts "---\n" - file.puts row['Blog Post'].gsub(" ", "\n\n") + file.puts row['Blog Post'].gsub(' ', "\n\n") end end