|
| 1 | +--- |
| 2 | + |
| 3 | +title: "Automating LiaScript Transformations on GitHub with Enhanced Workflows and Asset Generation" |
| 4 | +slug: automating-liascript-transformations-on-github |
| 5 | +date: 2025-03-24 |
| 6 | +draft: false |
| 7 | +author: André Dietrich |
| 8 | +image: "/images/post/automation-1.jpg" |
| 9 | + |
| 10 | +categories: |
| 11 | + - Community |
| 12 | + - Technology |
| 13 | + - Tools |
| 14 | + |
| 15 | +tags: |
| 16 | + - GitHub |
| 17 | + - Automation |
| 18 | + - LiaScript |
| 19 | + - PDF |
| 20 | + - SCORM |
| 21 | + - IMS |
| 22 | + - Workflow |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | + |
| 27 | +In today’s fast-paced development and educational environments, automation isn’t just a convenience—it’s a necessity. Automating the transformation of your LiaScript markdown documents into formats like PDFs, SCORM, and IMS packages can dramatically streamline your workflow. In this post, we dive deeper into GitHub Workflows: how they work, when they trigger, and what each part (triggers, jobs, steps, and assets) does. We also provide detailed code examples—from a simple "Hello LiaScript" echo to a fully functional pipeline that installs necessary tools, runs the LiaScript exporter, and packages multiple assets. |
| 28 | + |
| 29 | +## What Are GitHub Workflows? |
| 30 | + |
| 31 | +GitHub Workflows are at the heart of GitHub Actions. They allow you to automate tasks—such as building, testing, or deploying code—using a simple YAML file stored in your repository (usually under `.github/workflows`). Let’s break down the basics: |
| 32 | + |
| 33 | +### Key Concepts: |
| 34 | + |
| 35 | +- **Triggers:** |
| 36 | + |
| 37 | + A trigger defines the event that starts the workflow. For example, you can trigger a workflow on: |
| 38 | + |
| 39 | + - **Pushes** (e.g., every push to a branch) |
| 40 | + - **Pull Requests** |
| 41 | + - **Scheduled times** (using cron syntax) |
| 42 | + - **Manual triggers** (using workflow_dispatch) |
| 43 | + |
| 44 | +- **Jobs:** |
| 45 | + |
| 46 | + A job is a collection of steps that run in the same virtual environment (e.g., an Ubuntu machine). Jobs can run sequentially or in parallel. |
| 47 | + |
| 48 | +- **Steps:** |
| 49 | + |
| 50 | + Each job is made up of one or more steps. A step can either be a shell command or an action (pre-built task) that performs a specific function, such as checking out the code or uploading assets. |
| 51 | + |
| 52 | +- **Assets and Releases:** |
| 53 | + |
| 54 | + You can package the outputs of your workflow (e.g., PDFs, SCORM, IMS packages) as release assets. This is especially useful for distributing updated documentation or e-learning packages. |
| 55 | + |
| 56 | +### A Simple Example |
| 57 | + |
| 58 | +Below is a very basic YAML file that simply prints out "Hello LiaScript". Notice the comments that explain each part: |
| 59 | + |
| 60 | +```yaml |
| 61 | +# File: .github/workflows/hello-liascript.yml |
| 62 | +name: Hello LiaScript |
| 63 | + |
| 64 | +# This workflow triggers on every push to any branch. |
| 65 | +on: push |
| 66 | + |
| 67 | +jobs: |
| 68 | + hello: |
| 69 | + # The job will run on the latest Ubuntu runner. |
| 70 | + runs-on: ubuntu-latest |
| 71 | + |
| 72 | + steps: |
| 73 | + # Step 1: Print a simple greeting to the console. |
| 74 | + - name: Print Greeting |
| 75 | + run: echo "Hello LiaScript" |
| 76 | +``` |
| 77 | +
|
| 78 | +This example demonstrates the simplest workflow: one trigger, one job, and one step. |
| 79 | +
|
| 80 | +--- |
| 81 | +
|
| 82 | +## Enhancing the Workflow: Installing Tools and Running the LiaScript Exporter |
| 83 | +
|
| 84 | +Now let’s extend the simple workflow. The goal is to install Node.js and the LiaScript exporter, then run the exporter on your README file to generate a PDF. After that, we will add steps to create additional assets for SCORM and IMS packages. |
| 85 | +
|
| 86 | +### Extended Workflow Example |
| 87 | +
|
| 88 | +```yaml |
| 89 | +# File: .github/workflows/generate-liascript-outputs.yml |
| 90 | +name: Generate LiaScript Outputs |
| 91 | + |
| 92 | +# Trigger the workflow when changes are pushed to the 'main' branch. |
| 93 | +on: |
| 94 | + push: |
| 95 | + branches: |
| 96 | + - main |
| 97 | + |
| 98 | +jobs: |
| 99 | + generate: |
| 100 | + runs-on: ubuntu-latest |
| 101 | + |
| 102 | + steps: |
| 103 | + # Step 1: Check out the repository's code. |
| 104 | + - name: Checkout Repository |
| 105 | + uses: actions/checkout@v4 |
| 106 | + |
| 107 | + # Step 2: Set up Node.js environment. |
| 108 | + - name: Set up Node.js |
| 109 | + uses: actions/setup-node@v3 |
| 110 | + with: |
| 111 | + node-version: '16' # Specify the Node.js version to use. |
| 112 | + |
| 113 | + # Step 3: Install the LiaScript exporter globally using npm. |
| 114 | + - name: Install LiaScript Exporter |
| 115 | + run: | |
| 116 | + # Install the exporter tool |
| 117 | + npm install -g @liascript/exporter |
| 118 | +
|
| 119 | + # Step 4: Generate a PDF from the README.md using the exporter. |
| 120 | + - name: Generate PDF |
| 121 | + run: | |
| 122 | + # Use the LiaScript exporter to convert README.md to a PDF. |
| 123 | + liaex -i README.md --format pdf --output Documentation --pdf-timeout 1500000 |
| 124 | +
|
| 125 | + # Step 5: Generate a SCORM package. |
| 126 | + - name: Generate SCORM |
| 127 | + run: | |
| 128 | + # Convert the README.md to a SCORM package. |
| 129 | + liaex -i README.md --format scorm --output SCORM |
| 130 | +
|
| 131 | + # Step 6: Generate an IMS package. |
| 132 | + - name: Generate IMS Package |
| 133 | + run: | |
| 134 | + # Convert the README.md to an IMS package. |
| 135 | + liaex -i README.md --format ims --output IMS |
| 136 | +
|
| 137 | + # Step 7: Create a new release in GitHub to hold the generated assets. |
| 138 | + - name: Create New Release |
| 139 | + id: create_release |
| 140 | + uses: actions/create-release@v1 |
| 141 | + env: |
| 142 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 143 | + with: |
| 144 | + tag_name: 'latest' |
| 145 | + release_name: 'Latest LiaScript Documentation' |
| 146 | + draft: false |
| 147 | + prerelease: false |
| 148 | + |
| 149 | + # Step 8: Upload the generated PDF as a release asset. |
| 150 | + - name: Upload PDF as Release Asset |
| 151 | + uses: actions/upload-release-asset@v1 |
| 152 | + env: |
| 153 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 154 | + with: |
| 155 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 156 | + asset_path: ./Documentation/Documentation.pdf |
| 157 | + asset_name: Documentation.pdf |
| 158 | + asset_content_type: application/pdf |
| 159 | + |
| 160 | + # Step 9: Upload the generated SCORM package. |
| 161 | + - name: Upload SCORM as Release Asset |
| 162 | + uses: actions/upload-release-asset@v1 |
| 163 | + env: |
| 164 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + with: |
| 166 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 167 | + asset_path: ./SCORM/scorm.zip |
| 168 | + asset_name: scorm.zip |
| 169 | + asset_content_type: application/zip |
| 170 | + |
| 171 | + # Step 10: Upload the generated IMS package. |
| 172 | + - name: Upload IMS as Release Asset |
| 173 | + uses: actions/upload-release-asset@v1 |
| 174 | + env: |
| 175 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 176 | + with: |
| 177 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 178 | + asset_path: ./IMS/ims.zip |
| 179 | + asset_name: ims.zip |
| 180 | + asset_content_type: application/zip |
| 181 | +``` |
| 182 | +
|
| 183 | +### Detailed Explanation |
| 184 | +
|
| 185 | +1. **Repository Checkout and Environment Setup:** |
| 186 | + - **Checkout:** |
| 187 | + Uses the official checkout action to pull your repository’s code into the runner. |
| 188 | + - **Node.js Setup:** |
| 189 | + Sets up Node.js (v16 in this example) using the `actions/setup-node` action. This is necessary for running npm commands and installing global packages like the LiaScript exporter. |
| 190 | + |
| 191 | +2. **Installing and Running the Exporter:** |
| 192 | + - **Install LiaScript Exporter:** |
| 193 | + Installs the exporter globally. This tool converts your markdown into various formats. |
| 194 | + - **Generate PDF/SCORM/IMS:** |
| 195 | + Each of these steps runs the `liaex` command with different parameters: |
| 196 | + - **PDF:** Converts `README.md` into a PDF file. |
| 197 | + - **SCORM:** Converts `README.md` into a SCORM package (typically zipped). |
| 198 | + - **IMS:** Converts `README.md` into an IMS package. |
| 199 | + |
| 200 | +3. **Release Management:** |
| 201 | + - **Create Release:** |
| 202 | + Uses the `actions/create-release` action to generate a new release on GitHub, which acts as a container for your generated assets. |
| 203 | + - **Uploading Assets:** |
| 204 | + Uses `actions/upload-release-asset` to attach each file (PDF, SCORM, and IMS) to the release. Make sure that the file paths and names match the output of your exporter commands. |
| 205 | + |
| 206 | +--- |
| 207 | + |
| 208 | +## Understanding GitHub Workflow Triggers and Structure |
| 209 | + |
| 210 | +### Triggers |
| 211 | + |
| 212 | +A workflow is activated by specific events. Common triggers include: |
| 213 | + |
| 214 | +- **Push:** Every time you push commits to your repository. |
| 215 | +- **Pull Request:** When a pull request is opened or updated. |
| 216 | +- **Schedule:** Using a cron-like syntax (e.g., to run a job every day at midnight). |
| 217 | +- **Manual:** Triggered manually by a user with `workflow_dispatch`. |
| 218 | + |
| 219 | +You can combine triggers as needed. For example, the following YAML snippet shows both push and schedule triggers: |
| 220 | + |
| 221 | +```yaml |
| 222 | +on: |
| 223 | + push: |
| 224 | + branches: |
| 225 | + - main |
| 226 | + schedule: |
| 227 | + - cron: '0 0 * * *' # Runs every day at midnight UTC |
| 228 | +``` |
| 229 | + |
| 230 | +### Jobs and Steps |
| 231 | + |
| 232 | +- **Jobs:** |
| 233 | + Each job runs in its own virtual environment. Jobs can run sequentially (one after the other) or in parallel (independently). |
| 234 | + |
| 235 | +- **Steps:** |
| 236 | + Steps within a job are executed sequentially. A step can be: |
| 237 | + - A simple shell command. |
| 238 | + - An action (a reusable unit of work, like checking out code). |
| 239 | + - A script with inline comments to help explain what’s happening. |
| 240 | + |
| 241 | +Each step is designed to be clear and modular, so you can add, remove, or modify parts of your workflow without affecting other steps. |
| 242 | + |
| 243 | +### Assets in a Release |
| 244 | + |
| 245 | +When you generate files (like PDFs, SCORM packages, or IMS packages), you often want to share them as part of a GitHub release. This is done using the `actions/upload-release-asset` action. It takes several parameters: |
| 246 | + |
| 247 | +- **upload_url:** Provided by the release creation step. |
| 248 | +- **asset_path:** Local path to the file you wish to upload. |
| 249 | +- **asset_name:** Name the file will have in the release. |
| 250 | +- **asset_content_type:** MIME type of the file (e.g., `application/pdf` for PDFs). |
| 251 | + |
| 252 | +--- |
| 253 | + |
| 254 | +## Conclusion |
| 255 | + |
| 256 | +By leveraging GitHub Workflows, you can automate the transformation of LiaScript markdown documents into multiple output formats such as PDFs, SCORM, and IMS packages—all with a single YAML file. This powerful automation tool not only ensures consistency but also significantly reduces manual overhead. Start with the simple examples provided, and gradually extend your workflows to match the complexity of your project needs. |
| 257 | + |
| 258 | +Experiment with different triggers, add more jobs or steps as necessary, and customize the asset uploads to suit your release management strategy. Happy automating! |
| 259 | + |
0 commit comments