https://github.com/vpayno/github-gitlab-with-cuelang
Experiments in using Cuelang with GitHub Workflows/Actions and GitLab Pipelines.
https://github.com/vpayno/github-gitlab-with-cuelang
cuelang github-workflows runme-playbooks
Last synced: 7 months ago
JSON representation
Experiments in using Cuelang with GitHub Workflows/Actions and GitLab Pipelines.
- Host: GitHub
- URL: https://github.com/vpayno/github-gitlab-with-cuelang
- Owner: vpayno
- License: mit
- Created: 2024-03-06T01:10:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-08T02:45:01.000Z (over 1 year ago)
- Last Synced: 2025-01-19T06:26:20.010Z (9 months ago)
- Topics: cuelang, github-workflows, runme-playbooks
- Language: CUE
- Homepage:
- Size: 85.9 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# github-gitlab-with-cuelang
[](https://github.com/vpayno/github-gitlab-with-cuelang/actions/workflows/go.yml)
Experiments in using Cuelang with GitHub Workflows/Actions and GitLab Pipelines.
## Notes
- This is a runnable [Runme](https://github.com/stateful/runme) playbook.
## Dependencies
- [Cue CLI](https://github.com/cue-lang/cue)
```bash { background=false category=dependencies closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=install-dependency-cue promptEnv=true terminalRows=10 }
go install cuelang.org/go/cmd/cue@latest
```## JSON Schemas to Cue
Schema sources:
- [GitHub Workflow](https://json.schemastore.org/github-workflow.json)
```bash { background=false category=schema-import closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=schema-import-github promptEnv=true terminalRows=10 }
set -exmkdir -pv ./cue.mod/pkg/json.schemastore.org/github
cd ./cue.mod/pkg/json.schemastore.org/github
rm -fv ./github-workflow.json
wget -c https://json.schemastore.org/github-workflow.json
cue import --verbose --force --path '#Workflow:' --package github jsonschema: ./github-workflow.json
ls
```- [GitLab CI](https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json)
```bash { background=false category=schema-import closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=schema-import-gitlab promptEnv=true terminalRows=10 }
set -exmkdir -pv ./cue.mod/pkg/json.schemastore.org/gitlab
cd ./cue.mod/pkg/json.schemastore.org/gitlab
rm -fv ./gitlab-ci.json
wget -c https://gitlab.com/gitlab-org/gitlab/-/raw/master/app/assets/javascripts/editor/schema/ci.json -O ./gitlab-ci.json
cue import --verbose --force --path '#GitLabCi:' --package gitlab jsonschema: ./gitlab-ci.json
ls
```## Importing Workflows to Cue
This should only be run once. It's here as documentation and it was used for the original import.
```bash { background=false category=github-import closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=workflow-import-github promptEnv=true terminalRows=20 }
set -exif [[ -f .runme-lock-github-workflow-import ]]; then
gum confirm "GitHub Workflows were already imported. Re-Import?" || exit
ficd .github/workflows/
ls
cue import -f -p workflows -l 'strings.Replace(name, " ", "", -1)' ./*.yml
ls
touch "$(git rev-parse --show-toplevel)/.runme-lock-github-workflow-import"
```## Running `cue vet`
To validate the cue files:
```bash { background=false category=github-validate closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=workflow-vet-github promptEnv=true terminalRows=10 }
set -excd .github/workflows/
ls
cue vet || { printf "\n"; cue vet -c; }
```## Running `cue export`
To test the cue files:
```bash { background=false category=github-validate closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=workflow-test-github promptEnv=true terminalRows=10 }
set -excd .github/workflows/
ls
cue export | less
```## Running `cue trim`
To trim the exported data:
```bash { background=false category=github-trim closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=workflow-trim-github promptEnv=true terminalRows=10 }
set -excd .github/workflows/
ls
cue trim
ls
git diff .
```## Generating Workflows from Cue Data
To export the workflows run the following command:
```bash { background=false category=github-export closeTerminalOnSuccess=false excludeFromRunAll=true interactive=true interpreter=bash name=workflow-export-github promptEnv=true terminalRows=10 }
set -excd .github/workflows/
ls
cue cmd genworkflows
ls
git diff .
```