Compare commits
	
		
			6 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 79d46bdad1 | |||
| 74a724c287 | |||
| 6c3889d2a0 | |||
| dcaa4a7365 | |||
| 3e48f9c97c | |||
| 8402546cf8 | 
							
								
								
									
										90
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| <h1>SpyglassMC Action</h1> | ||||
|  | ||||
| This action lets you validate your Minecraft datapack using [SpyglassMC](https://spyglassmc.com/). | ||||
| All JSON and MCFunction files are checked for syntax errors. | ||||
|  | ||||
| <details> | ||||
| <summary><strong>Table of Contents</strong></summary> | ||||
|  | ||||
| --- | ||||
| - [Basic workflow](#basic-workflow) | ||||
| - [Input parameters](#input-parameters) | ||||
| - [GitHub vs. Gitea](#github-vs-gitea) | ||||
|   - [Gitea](#gitea) | ||||
|   - [GitHub](#github) | ||||
| --- | ||||
|  | ||||
| </details> | ||||
|  | ||||
|  | ||||
| ## Basic workflow | ||||
| Here is a simple example showing how to use this action: | ||||
|  | ||||
| ```yaml | ||||
| name: Check datapack | ||||
| on: | ||||
|   pull_request: | ||||
|     branches: | ||||
|       - main | ||||
| jobs: | ||||
|   check: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - name: Checkout code | ||||
|         uses: actions/checkout@v4 | ||||
|  | ||||
|       - name: Check syntax and schemas | ||||
|         uses: https://git.kb28.ch/HEL/spyglassmc-action@v1.1.4 | ||||
| ``` | ||||
|  | ||||
| ## Input parameters | ||||
| The following parameters can be passed using the `with` section: | ||||
| |Parameter|Type|Default|Description| | ||||
| |:---|:---|:---:|:---| | ||||
| |`rootDir`        |Path   |`./`   |Root datapack directory (containing the data folder and pack.mcmeta file)| | ||||
| |`version`        |String |`auto` |The Minecraft version to use. If not specified or set to 'auto', will try to use the version indicated in `pack.mcmeta`| | ||||
| |`reportAllErrors`|Boolean|`false`|Whether to report all errors or only the first one| | ||||
| |`verbose`        |Boolean|`false`|Whether to provide details on errors or just the number of errors| | ||||
|  | ||||
|  | ||||
| ## GitHub vs. Gitea | ||||
|  | ||||
| Depending on where you want to execute this action, you should be mindful of the following points | ||||
|  | ||||
| ### Gitea | ||||
| If your workflow will be running on Gitea, you might need to set a specific runner image (see https://gitea.com/gitea/runner-images#migration). For example: | ||||
| ```yaml | ||||
| ... | ||||
| jobs: | ||||
|   check: | ||||
|     runs-on: ubuntu-latest | ||||
|     container: catthehacker/ubuntu:act-latest | ||||
| ... | ||||
| ``` | ||||
|  | ||||
| ### GitHub | ||||
| If your workflow will be running on GitHub, you will not be able to simply use the action from this Gitea repository.\ | ||||
| Instead, you need to add a step to clone this repository, and use the action locally | ||||
|  | ||||
| ```yaml | ||||
| name: Check datapack | ||||
| on: | ||||
|   pull_request: | ||||
|     branches: | ||||
|       - main | ||||
| jobs: | ||||
|   deploy: | ||||
|     runs-on: ubuntu-latest | ||||
|     steps: | ||||
|       - name: Checkout code | ||||
|         uses: actions/checkout@v4 | ||||
|  | ||||
|       - name: Checkout action | ||||
|         run: | | ||||
|           git clone https://git.kb28.ch/HEL/spyglassmc-action ./.github/actions/spyglassmc-action | ||||
|  | ||||
|       - name: Check syntax and schemas | ||||
|         uses: ./.github/actions/spyglassmc-action | ||||
| ``` | ||||
|  | ||||
| You might also want to `git checkout` a specific tagged version | ||||
							
								
								
									
										10
									
								
								action.yml
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								action.yml
									
									
									
									
									
								
							| @@ -15,7 +15,15 @@ inputs: | ||||
|     description: The Minecraft version to use. If not specified or set to 'auto', will try to use the version indicated in `pack.mcmeta` | ||||
|     required: false | ||||
|     default: 'auto' | ||||
|   reportAllErrors: | ||||
|     description: Whether to report all errors or only the first one | ||||
|     required: false | ||||
|     default: 'false' | ||||
|   verbose: | ||||
|     description: Whether to provide details on errors or just the number of errors | ||||
|     required: false | ||||
|     default: 'false' | ||||
|  | ||||
| runs: | ||||
|   using: 'node24' | ||||
|   using: 'node20' | ||||
|   main: 'dist/index.js' | ||||
|   | ||||
							
								
								
									
										2
									
								
								dist/check_datapack.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/check_datapack.d.ts
									
									
									
									
										vendored
									
									
								
							| @@ -19,7 +19,7 @@ export declare class CustomService extends core.Service { | ||||
|     private getFileContent; | ||||
|     private getLineAndColumn; | ||||
|     private getErrorProperties; | ||||
|     checkFile(path: string, lang: string): Promise<boolean>; | ||||
|     checkFile(filePath: string, lang: string): Promise<boolean>; | ||||
|     checkAllFiles(): Promise<boolean>; | ||||
| } | ||||
| export declare function checkDatapack(rootDir: string, version: string, reportAll: boolean, verbose: boolean): Promise<void>; | ||||
|   | ||||
							
								
								
									
										2
									
								
								dist/check_datapack.d.ts.map
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/check_datapack.d.ts.map
									
									
									
									
										vendored
									
									
								
							| @@ -1 +1 @@ | ||||
| {"version":3,"file":"","sourceRoot":"","sources":["file:///home/louis/Documents/spyglassmc-action/src/check_datapack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AAQxC,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,eAAe,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;CACnB;AAkBD,qBAAa,aAAc,SAAQ,IAAI,CAAC,OAAO;IAC3C,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa;IAiD9D,QAAQ;IAMd,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,kBAAkB;IAUpB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IA+BvD,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;CA2B1C;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzH"} | ||||
| {"version":3,"file":"","sourceRoot":"","sources":["file:///home/louis/Documents/spyglassmc-action/src/check_datapack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AAQxC,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,eAAe,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAA;CACnB;AAkBD,qBAAa,aAAc,SAAQ,IAAI,CAAC,OAAO;IAC3C,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,aAAa,CAAA;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa;IAiD9D,QAAQ;IAMd,OAAO,CAAC,oBAAoB;IAI5B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,kBAAkB;IAUpB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgC3D,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC;CA2B1C;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBzH"} | ||||
							
								
								
									
										17
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										17
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							| @@ -87590,23 +87590,24 @@ class CustomService extends Service { | ||||
|             endLine, endColumn | ||||
|         }; | ||||
|     } | ||||
|     async checkFile(path, lang) { | ||||
|         const url = this.makeFileUrl(path); | ||||
|         const content = this.getFileContent(path); | ||||
|     async checkFile(filePath, lang) { | ||||
|         const url = this.makeFileUrl(filePath); | ||||
|         const content = this.getFileContent(filePath); | ||||
|         this.project.onDidOpen(url, lang, 0, content); | ||||
|         const docAndNode = this.project.getClientManaged(url); | ||||
|         if (!docAndNode) { | ||||
|             core.error(`File ${path} is not loaded`); | ||||
|             core.error(`File ${filePath} is not loaded`); | ||||
|             return false; | ||||
|         } | ||||
|         const { node } = docAndNode; | ||||
|         const errors = FileNode.getErrors(node); | ||||
|         if (errors.length !== 0) { | ||||
|             const msg = `${errors.length} error${errors.length > 1 ? "s" : ""} in ${path}`; | ||||
|             const relPath = external_path_default().relative(this.rootDir, filePath); | ||||
|             const msg = `${errors.length} error${errors.length > 1 ? "s" : ""} in ${relPath}`; | ||||
|             if (this.options.verbose) { | ||||
|                 core.startGroup(msg); | ||||
|                 for (const err of errors) { | ||||
|                     core.error(err.message, this.getErrorProperties(err, path, content)); | ||||
|                     core.error(err.message, this.getErrorProperties(err, filePath, content)); | ||||
|                 } | ||||
|                 core.endGroup(); | ||||
|             } | ||||
| @@ -87625,7 +87626,7 @@ class CustomService extends Service { | ||||
|             `- Function: ${funcFiles.length}`); | ||||
|         let success = true; | ||||
|         for (const jsonFile of jsonFiles) { | ||||
|             if (!this.checkFile(jsonFile, "json")) { | ||||
|             if (!(await this.checkFile(jsonFile, "json"))) { | ||||
|                 success = false; | ||||
|                 if (!this.options.reportAllErrors) { | ||||
|                     return false; | ||||
| @@ -87633,7 +87634,7 @@ class CustomService extends Service { | ||||
|             } | ||||
|         } | ||||
|         for (const funcFile of funcFiles) { | ||||
|             if (!this.checkFile(funcFile, "mcfunction")) { | ||||
|             if (!(await this.checkFile(funcFile, "mcfunction"))) { | ||||
|                 success = false; | ||||
|                 if (!this.options.reportAllErrors) { | ||||
|                     return false; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "spyglassmc-action", | ||||
|   "version": "1.1.0", | ||||
|   "version": "1.1.4", | ||||
|   "description": "Check your Minecraft datapack for syntax or schema errors using SpyglassMC", | ||||
|   "main": "index.js", | ||||
|   "scripts": { | ||||
|   | ||||
| @@ -125,26 +125,27 @@ export class CustomService extends core.Service { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     async checkFile(path: string, lang: string): Promise<boolean> { | ||||
|         const url = this.makeFileUrl(path) | ||||
|         const content = this.getFileContent(path) | ||||
|     async checkFile(filePath: string, lang: string): Promise<boolean> { | ||||
|         const url = this.makeFileUrl(filePath) | ||||
|         const content = this.getFileContent(filePath) | ||||
|         this.project.onDidOpen(url, lang, 0, content) | ||||
|         const docAndNode = this.project.getClientManaged(url) | ||||
|         if (!docAndNode) { | ||||
|             action.error(`File ${path} is not loaded`) | ||||
|             action.error(`File ${filePath} is not loaded`) | ||||
|             return false | ||||
|         } | ||||
|         const { node } = docAndNode | ||||
|         const errors = core.FileNode.getErrors(node) | ||||
|         if (errors.length !== 0) { | ||||
|             const msg = `${errors.length} error${errors.length > 1 ? "s" : ""} in ${path}` | ||||
|             const relPath = path.relative(this.rootDir, filePath) | ||||
|             const msg = `${errors.length} error${errors.length > 1 ? "s" : ""} in ${relPath}` | ||||
|              | ||||
|             if (this.options.verbose) { | ||||
|                 action.startGroup(msg) | ||||
|                 for (const err of errors) { | ||||
|                     action.error( | ||||
|                         err.message, | ||||
|                         this.getErrorProperties(err, path, content) | ||||
|                         this.getErrorProperties(err, filePath, content) | ||||
|                     ) | ||||
|                 } | ||||
|                 action.endGroup() | ||||
| @@ -166,7 +167,7 @@ export class CustomService extends core.Service { | ||||
|         ) | ||||
|         let success = true | ||||
|         for (const jsonFile of jsonFiles) { | ||||
|             if (!this.checkFile(jsonFile, "json")) { | ||||
|             if (!(await this.checkFile(jsonFile, "json"))) { | ||||
|                 success = false | ||||
|                 if (!this.options.reportAllErrors) { | ||||
|                     return false | ||||
| @@ -174,7 +175,7 @@ export class CustomService extends core.Service { | ||||
|             } | ||||
|         } | ||||
|         for (const funcFile of funcFiles) { | ||||
|             if (!this.checkFile(funcFile, "mcfunction")) { | ||||
|             if (!(await this.checkFile(funcFile, "mcfunction"))) { | ||||
|                 success = false | ||||
|                 if (!this.options.reportAllErrors) { | ||||
|                     return false | ||||
|   | ||||
		Reference in New Issue
	
	Block a user