Skip to content

updated github actions #13

updated github actions

updated github actions #13

Workflow file for this run

# Name of the workflow
name: Build and Compile Jsonnet
# Define the events that trigger the workflow
on:
push:
# Trigger the workflow when changes are pushed to any .jsonnet file in the repository
paths:
- "**.jsonnet" # Trigger only for .jsonnet file changes
pull_request:
# Trigger the workflow when a pull request modifies any .jsonnet file in the repository
paths:
- "**.jsonnet" # Trigger only for .jsonnet file changes in pull requests
workflow_dispatch:
# Allow the workflow to be manually triggered from the GitHub UI
# (e.g., by clicking the "Run workflow" button). No additional settings needed.
jobs:
build:
runs-on: ubuntu-latest # The workflow will run on the latest version of Ubuntu (GitHub-hosted runner)
# Define only the environment variables that are actively used
env:
JSONNET_FILE: "jsonnet/windows-mac-remap.jsonnet" # Path to the specific Jsonnet file to compile
OUTPUT_FILE: "config/windows-keyboard.json" # Path to the specific output .json file
steps:
# Step 1: Checkout the repository code so the workflow can access the files
- name: Checkout code
uses: actions/checkout@v3 # This action checks out the repository's code to the runner's workspace
# Step 2: Set up Go (using stable version)
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable" # Specify that the latest stable version of Go should be installed
# Step 3: Install Jsonnet and Jsonnet Lint
- name: Install Jsonnet and Jsonnet Lint
run: |
# Install Jsonnet and Jsonnet Lint using Go's package manager
go install github.com/google/go-jsonnet/cmd/jsonnet@latest # Install Jsonnet tool
go install github.com/google/go-jsonnet/cmd/jsonnet-lint@latest # Install Jsonnet Lint tool
# Step 4: Run the build script to generate JSON files from Jsonnet
- name: Compile Jsonnet files
run: |
# Make sure the build script is executable
chmod +x ./scripts/build-jsonnet.sh # Ensure the build script has execution permissions
# Run the build script to compile the .jsonnet file into a .json file
./scripts/build-jsonnet.sh # This script will take care of the Jsonnet compilation process
# Step 5: Check for changes in .jsonnet or .json files and commit/push if necessary
- name: Check for changes and push compiled JSON files
run: |
# Check for any changes in the .jsonnet file or the output .json file
if git diff --exit-code --quiet -- "${{ env.JSONNET_FILE }}" "${{ env.OUTPUT_FILE }}"; then
# If no changes are detected, exit the workflow early to save processing time
echo "No updates to .jsonnet or .json files, exiting." # Output message indicating no changes
exit 0 # Exit without continuing to the build and push steps
else
# Configure Git user for commits made by GitHub Actions
git config user.name github-actions # Set the Git user name as "github-actions"
git config user.email github-actions@github.com # Set the Git email as GitHub Actions default email
# Stage the generated .json file for commit
git add "${{ env.OUTPUT_FILE }}" # Stage the specific output .json file
# Commit the changes with a message that indicates the update from the Jsonnet build
git commit -m "Build and update JSON files from Jsonnet"
# Push the committed changes to the repository
git push # This will push the changes to the remote repository on GitHub
fi