Skip to content

IBM Courses and Match with Credly Badges

Raydo Matthee edited this page May 23, 2024 · 2 revisions

Below is the enhanced Markdown document with badges, title, subtitle, author information, and date. The document is designed to be visually appealing for a GitHub Wiki page.

Update IBM Courses and Match with Credly Badges

GitHub Actions IBM Courses Credly Badges GitHub Wiki

Created by Raydo M, May 23, 2024


Table of Contents

  1. Purpose
  2. Workflow Overview
  3. Directory Structure
  4. File Contents
  5. Process Explanation
  6. Expected Outcomes
  7. Best Practices
  8. Summary

Purpose

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.


Workflow Overview

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.

GitHub Actions Workflow

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()}.'
            })

Directory Structure

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

File Contents

Below are the contents of each file required for this workflow.

.github/workflows/update_courses_and_badges.yml

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()}.'
            })

match_courses_to_badges.py

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()

requirements.txt

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

Process Explanation

  1. Checkout Repository: The repository is checked out using actions/checkout@v4 to ensure the latest code is available for the workflow.
  2. Fetch IBM Courses: IBM courses are fetched from a specified URL and saved as course_feed.json.
  3. 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.
  4. Set up Python: Python is set up using actions/setup-python@v2 to ensure the correct Python version is available.
  5. Install Dependencies: Python dependencies listed in requirements.txt are installed.
  6. 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.
  7. Commit and Push Updates: Any changes made to the repository (such as the updated CSV file) are committed and pushed back to the repository.
  8. Notify Update: A GitHub issue is created to notify about the update, providing a timestamp of when the update occurred.

Expected Outcomes

  • 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.

Best Practices

  • 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.

Summary

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 document is now enhanced with badges, author information, and a structured table of contents to improve readability and presentation on a GitHub Wiki page.