Scripts for the actions monorepo¶
There are currently two scripts for the actions monorepo:
- import_configs.sh
- monorepo_updates.sh
The scripts update (and use) a import-config.yml file, which is stored for each individual action.
Table of Contents - Import Config File Specifications - Import Configs Script - Monorepo Updates Script
Import Config File Specifications¶
The import-config.yml file is a structured YAML configuration file generated or updated by the import_configs.sh script; the file is also updated by the monorepo_updates.sh script. The import-config.yml file provides metadata and specifications for GitHub Actions, whether they are locally created or imported from external sources. Below is a breakdown of its structure and an example/template:
File Structure¶
- Metadata Fields:
name: The name of the action (derived from the directory name).author: The author of the action. If not specified, a placeholder is used.description: A brief description of the action. Defaults to "placeholder" if not provided.-
group: The name of the parent directory group. -
Import Status:
-
imported: A boolean indicating if the action is imported (true) or locally created (false). -
Source Information (if
importedistrue): source.action_name: The name of the imported action.source.author: The author of the source action.source.repo_name: The name of the GitHub repository containing the action.source.repo_url: The URL of the source repository.source.current_version: The version currently in use.source.latest_version: The latest available version of the action.-
source.update_available: Boolean indicating if an update is available. -
Local Modifications:
local.author: The author of the local action (if not imported).local.modifications: Boolean indicating if modifications have been made.-
local.update.exclusions: A list of files to exclude when updating from source. -
Specifications:
specs.action_file: The name of the action file (action.ymloraction.yaml).specs.inputs: A list of input keys defined in the action.specs.outputs: A list of output keys defined in the action.specs.runs.using: The execution environment (e.g.,node12,docker).-
specs.runs.main: The entry point file for the action (if applicable). -
Tests:
tests._comment: A reserved section for future test-related fields.
Example import-config.yml¶
name: example-action
author: "john-doe"
description: "An example GitHub Action for demonstration purposes."
group: "example-group"
imported: true
source:
action_name: "example-action"
author: "external-author"
repo_name: "example-repo"
repo_url: "https://github.com/external-author/example-repo"
current_version: "v1.0.0"
latest_version: "v1.1.0"
update_available: true
monorepo: true
monorepo_path: "example/"
local:
author: "john-doe"
modifications: false
update:
exclusions:
- README-examples.md
- example-custom-notes.md
specs:
action_file: "action.yml"
inputs: ["input1", "input2"]
outputs: ["output1"]
runs:
using: "node20"
main: "dist/index.js"
tests:
_comment: "reserved for future use"
Notes¶
- Placeholders: If the script cannot determine certain values, placeholders (
"placeholder") are inserted to prompt the user for manual updates. - Dynamic Updates: For imported actions, fields such as
source.latest_versionandsource.update_availableare dynamically updated based on the GitHub API. - Flexibility: The file structure accommodates both locally created and imported actions, ensuring versatility in various workflows.
Import Configs Script¶
The import_configs.sh script automates the creation and maintenance of import-config.yml files for actions found in specified directories. It achieves the following:
- Read Configuration:
-
Reads target directories from a configuration file
target_dirs.conf. -
Identify Action Files:
-
Checks each subdirectory for the presence of an
action.ymloraction.yamlfile. -
Process
import-config.yml: -
For each subdirectory:
- If
import-config.ymlexists: - Updates fields like
author,description,specs(includinginputs,outputs,runs), andsource(if applicable). - Checks for updates if the action is marked as "imported" by querying the GitHub API for the latest release.
- If
import-config.ymldoes not exist: - Prompts the user to specify if the action is "imported" or "local."
- Generates an initial
import-config.ymlwith fields such asauthor,group,imported,specs, and optionally,sourcedetails for imported actions.
- If
-
Extract and Format Data:
- Uses the
yqtool to parse and extract data from YAML files and to update/create YAML fields. -
Extracts keys (e.g.,
inputs,outputs) and converts them into a suitable format for YAML. -
GitHub Integration:
-
For imported actions, fetches the latest version information from GitHub API to determine if an update is available.
-
Handle User Input:
-
Prompts the user to input metadata when creating
import-config.ymlfor new actions, especially for imported actions. -
Iterate Over All Actions:
-
Processes every subdirectory in the target directories, ensuring that all actions are updated or have an
import-config.ymlgenerated. -
Placeholder Values:
-
Inserts placeholders for fields like
authorordescriptionif they are missing in the action file. -
Reserved Tests Section:
-
Adds a
testsblock in theimport-config.ymlfile for future use. -
Output:
- Displays progress and completion messages for each action processed.
Notes¶
This script is designed to be extensible and works efficiently for managing configurations of multiple GitHub Actions. It uses yq for YAML manipulation, jq for JSON parsing, and assumes user access to GitHub API for imported action metadata.
Monorepo Updates Script¶
This script automates the process of checking for updates in repositories and applying those updates to the actions monorepo based on configurations specified in import-config.yml files within target directories. It achieves the following:
- Configuration Loading:
- Reads target directories from
target_dirs.conf. -
Optionally allows specifying a specific group and action to process instead of using all target directories.
-
Update Check Logic:
-
For each
import-config.ymlfile found in the target directories:- Checks if the action is "imported."
- Verifies if an update is available by comparing the current version with the latest version.
- Fetches the latest version information from the repository using GitHub APIs (via
curlandjq).
-
Repository Update Process:
- Clones the repository at the specified latest version.
- Processes the repository:
- Renames
.github/directory to__dot_github/and disables.ymlfiles within. - Adds a repository name prefix to
.mdand.ymlfiles.
- Renames
- Creates a new branch in the actions monorepo for the update.
-
Generates a new
README.mdbased on a template (imported_readme_template.md), usingsedto populate placeholders with details (e.g., group name, action name, new version).- Eventually this will be managed by a workflow within the actions repo.
-
Git Workflow:
- Prepares changes for a commit (does not auto-commit or push).
-
Provides instructions for the user to commit and push changes manually.
-
Temporary Directory Management:
- Uses a temporary directory for processing repository updates.
-
Prompts the user for cleanup after processing.
-
Configuration File Update:
- Updates the
current_versionandupdate_availablefields inimport-config.ymlafter successful processing.
Notes¶
The script also has some interactive features: - Prompts the user for specifying specific actions to update. - Offers manual intervention for committing, pushing changes, and cleaning up temporary directories.