Skip to content

Latest commit

 

History

History
203 lines (156 loc) · 6.21 KB

File metadata and controls

203 lines (156 loc) · 6.21 KB

Below is a comprehensive Markdown file (update_ibm_courses_and_badges.md) that includes the GitHub Actions workflow for updating IBM courses and matching them with Credly badges. It also describes the directory structure, file contents, and the necessary Python requirements.

Update IBM Courses and Match with Credly Badges

This document provides the details of the GitHub Actions workflow to update IBM courses and match them with Credly badges, along with the necessary directory structure and file contents.

GitHub Actions Workflow

The following workflow is scheduled to run daily at midnight UTC and can also be triggered manually from the GitHub UI.

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 "you@example.com"
          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

Here is the expected directory structure:

your-project-directory/
│
├── .github/
│   └── workflows/
│       └── update_courses_and_badges.yml
├── match_courses_to_badges.py
└── requirements.txt

File Contents

.github/workflows/update_courses_and_badges.yml

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 "you@example.com"
          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 is an example of what your match_courses_to_badges.py script might look like:

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

requests==2.28.2
pandas==2.0.1
numpy==1.24.2

Summary

This document outlines the necessary steps and files to create a GitHub Actions workflow that updates IBM courses and matches them with Credly badges. Ensure all files are placed in the correct directory structure for the workflow to function correctly. Customize the workflow and script as needed to fit your specific requirements.


Save this content in a file named `update_ibm_courses_and_badges.md`. This Markdown file provides a comprehensive guide, including the GitHub Actions workflow, the Python script, and the `requirements.txt` file.