forked from galaxyproject/training-material
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request galaxyproject#4681 from galaxyproject/jamnapari-or…
…dinal Implement GTN News posting via Google Form
- Loading branch information
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
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,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/ |
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,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 |
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
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
24 changes: 24 additions & 0 deletions
24
news/_posts/2024-01-29-simplified-gtn-news-submission-via-google-form.md
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,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. |