-
Notifications
You must be signed in to change notification settings - Fork 0
About IBM Courses
Created by Raydo M, May 23, 2024
- Purpose
- Workflow Overview
- Directory Structure
- File Contents
- Process Explanation
- Expected Outcomes
- Best Practices
- Summary
The purpose of this workflow is to automate the process of fetching the latest IBM courses and Credly badges, matching them, and updating the repository with this information. This ensures that the data is always up-to-date and accessible for further analysis or integration into other systems.
The GitHub Actions workflow is scheduled to run daily at midnight UTC and can also be triggered manually from the GitHub UI. This automation helps in maintaining an updated list of IBM courses and their corresponding Credly badges.
The following YAML code defines the GitHub Actions workflow.
name: Update IBM Courses and Match with Credly Badges
on:
schedule:
- cron: '0 0 * * *' # This will run the workflow daily at midnight UTC.
workflow_dispatch: # This allows you to manually trigger the workflow from the GitHub UI.
jobs:
fetch_and_process_data:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch IBM Courses
run: |
curl -o course_feed.json https://www.ibm.com/training/files/GTPjson/CourseFeed_Global.json
- name: Fetch Credly Badges
env:
CREDLY_TOKEN: ${{ secrets.CREDLY_TOKEN }}
run: |
curl -u "$CREDLY_TOKEN:" -X GET "https://api.credly.com/v1/badges" -H "Accept: application/json" -o badges.json
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Match Courses to Badges
run: python match_courses_to_badges.py
- name: Commit and Push Updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git add -A
git commit -m "Updated IBM courses and matched badges" || echo "No changes to commit"
git push
- name: Notify Update
uses: actions/github-script@v6
with:
script: |
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'IBM Courses and Badges Update',
body: 'IBM courses and matched badges were updated on ${new Date().toISOString()}.'
})
Organize your project directory as follows to ensure the workflow functions correctly.
your-project-directory/
│
├── .github/
│ └── workflows/
│ └── update_courses_and_badges.yml
├── match_courses_to_badges.py
└── requirements.txt
Below are the contents of each file required for this workflow.
This YAML file defines the GitHub Actions workflow.
name: Update IBM Courses and Match with Credly Badges
on:
schedule:
- cron: '0 0 * * *' # This will run the workflow daily at midnight UTC.
workflow_dispatch: # This allows you to manually trigger the workflow from the GitHub UI.
jobs:
fetch_and_process_data:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch IBM Courses
run: |
curl -o course_feed.json https://www.ibm.com/training/files/GTPjson/CourseFeed_Global.json
- name: Fetch Credly Badges
env:
CREDLY_TOKEN: ${{ secrets.CREDLY_TOKEN }}
run: |
curl -u "$CREDLY_TOKEN:" -X GET "https://api.credly.com/v1/badges" -H "Accept: application/json" -o badges.json
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Match Courses to Badges
run: python match_courses_to_badges.py
- name: Commit and Push Updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git add -A
git commit -m "Updated IBM courses and matched badges" || echo "No changes to commit"
git push
- name: Notify Update
uses: actions/github-script@v6
with:
script: |
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'IBM Courses and Badges Update',
body: 'IBM courses and matched badges were updated on ${new Date().toISOString()}.'
})
This Python script fetches the IBM courses and Credly badges, matches them, and saves the results to a CSV file.
import json
import pandas as pd
def load_data():
with open('course_feed.json', 'r') as f:
courses = json.load(f)
with open('badges.json', 'r') as f:
badges = json.load(f)
return courses, badges
def match_courses_to_badges(courses, badges):
# Example matching logic
matches = []
for course in courses['courses']:
for badge in badges['data']:
if course['title'] in badge['name']:
matches.append((course['title'], badge['name']))
return matches
def main():
courses, badges = load_data()
matches = match_courses_to_badges(courses, badges)
# Save the matches to a CSV file
df = pd.DataFrame(matches, columns=['Course', 'Badge'])
df.to_csv('course_badge_matches.csv', index=False)
if __name__ == "__main__":
main()
This file lists the Python dependencies required for the match_courses_to_badges.py
script.
requests==2.28.2
pandas==2.0.1
numpy==1.24.2
-
Checkout Repository: The repository is checked out using
actions/checkout@v4
to ensure the latest code is available for the workflow. -
Fetch IBM Courses: IBM courses are fetched from a specified URL and saved as
course_feed.json
. -
Fetch Credly Badges: Credly badges are fetched using the Credly API with a token stored in GitHub Secrets, and the data is saved as
badges.json
. -
Set up Python: Python is set up using
actions/setup-python@v2
to ensure the correct Python version is available. -
Install Dependencies: Python dependencies listed in
requirements.txt
are installed. -
Match Courses to Badges: The Python script
match_courses_to_badges.py
is executed to match IBM courses to Credly badges and save the results. - Commit and Push Updates: Any changes made to the repository (such as the updated CSV file) are committed and pushed back to the repository.
- Notify Update: A GitHub issue is created to notify about the update, providing a timestamp of when the update occurred.
- Up-to-date Data: The repository will have the latest IBM courses and their corresponding Credly badges updated daily.
- Automation: The process is fully automated, reducing the need for
manual intervention.
- Notifications: Automated notifications via GitHub issues ensure that updates are communicated promptly.
- Secure Secrets Management: Use GitHub Secrets to store sensitive information like the Credly API token.
- Error Handling: Implement error handling in the Python script to manage potential issues with data fetching and processing.
- Version Control: Commit changes regularly to ensure that updates are tracked and can be rolled back if necessary.
- Documentation: Maintain clear documentation of the workflow and scripts to facilitate maintenance and updates.
This document outlines the steps and best practices for setting up a GitHub Actions workflow to update IBM courses and match them with Credly badges. By following this guide, you can ensure that your data is consistently up-to-date and managed efficiently.
Feel free to customize the workflow and script as needed to fit your specific requirements.
Created by Raydo M, May 23, 2024
This version of the document is enhanced with badges, a structured table of contents, and additional sections for better readability and visual appeal on a GitHub Wiki page.
Skunkworks (Pty) Ltd, Johannesburg, South Africa
📞: +27 (12) 883 3663 | 📧: [email protected]
© 2023 Skunkworks (Pty) Ltd. All rights reserved.