chore: update @actions/core to v3 and convert to ESM
This commit updates the @actions/core dependency from v2 to v3. The primary change in @actions/core v3 is that it is now an ESM-only package. To maintain compatibility, the following changes were made: - Added "type": "module" to package.json to switch the project to ESM. - Converted index.js from CommonJS to ESM, replacing require with import/export. - Converted __tests__/index.test.js to ESM to support testing the updated index.js. - Re-built the production bundle in dist/ using ncc to reflect the changes. - Updated the main entry point check in index.js to use import.meta.url for ESM compatibility. This ensures the action continues to function correctly with the latest GitHub Actions toolkit library.
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
const {
|
import {
|
||||||
validateAuthentication,
|
validateAuthentication,
|
||||||
replacePlaceholders,
|
replacePlaceholders,
|
||||||
readReplaceAndWriteFiles,
|
readReplaceAndWriteFiles,
|
||||||
readFilesIntoDict,
|
readFilesIntoDict,
|
||||||
} = require("../index");
|
} from "../index.js";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
const os = require("os");
|
import os from "os";
|
||||||
const { glob } = require("glob");
|
import { glob } from "glob";
|
||||||
|
|
||||||
describe("validateAuthentication", () => {
|
describe("validateAuthentication", () => {
|
||||||
it("should return null when only token is provided", () => {
|
it("should return null when only token is provided", () => {
|
||||||
|
|||||||
11
dist/index.js
vendored
11
dist/index.js
vendored
File diff suppressed because one or more lines are too long
3
dist/package.json
vendored
Normal file
3
dist/package.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"type": "module"
|
||||||
|
}
|
||||||
32
index.js
32
index.js
@@ -1,8 +1,9 @@
|
|||||||
const { ScreepsAPI } = require("screeps-api");
|
import { ScreepsAPI } from "screeps-api";
|
||||||
const core = require("@actions/core");
|
import * as core from "@actions/core";
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const { glob } = require("glob");
|
import { glob } from "glob";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
|
import { fileURLToPath } from "url";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces specific placeholder strings within the provided content with corresponding dynamic values.
|
* Replaces specific placeholder strings within the provided content with corresponding dynamic values.
|
||||||
@@ -17,7 +18,7 @@ const path = require("path");
|
|||||||
* @param {string} content - The string content in which placeholders are to be replaced.
|
* @param {string} content - The string content in which placeholders are to be replaced.
|
||||||
* @returns {string} The content with placeholders replaced by their respective dynamic values.
|
* @returns {string} The content with placeholders replaced by their respective dynamic values.
|
||||||
*/
|
*/
|
||||||
function replacePlaceholders(content, hostname) {
|
export function replacePlaceholders(content, hostname) {
|
||||||
const deployTime = new Date().toISOString();
|
const deployTime = new Date().toISOString();
|
||||||
return content
|
return content
|
||||||
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
.replace(/{{gitHash}}/g, process.env.GITHUB_SHA)
|
||||||
@@ -37,7 +38,7 @@ function replacePlaceholders(content, hostname) {
|
|||||||
* @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory.
|
* @param {string} [prefix] - An optional directory prefix to prepend to the glob pattern. This allows searching within a specific directory.
|
||||||
* @returns {Promise<string[]>} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails.
|
* @returns {Promise<string[]>} A promise that resolves with an array of file paths that were processed, or rejects with an error if the process fails.
|
||||||
*/
|
*/
|
||||||
async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
export async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
||||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
const files = await glob(globPattern);
|
const files = await glob(globPattern);
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ async function readReplaceAndWriteFiles(pattern, prefix, hostname) {
|
|||||||
* @param {string} prefix - Directory prefix for file paths.
|
* @param {string} prefix - Directory prefix for file paths.
|
||||||
* @returns {Promise<Object>} - Promise resolving to a dictionary of file contents keyed by filenames.
|
* @returns {Promise<Object>} - Promise resolving to a dictionary of file contents keyed by filenames.
|
||||||
*/
|
*/
|
||||||
async function readFilesIntoDict(pattern, prefix) {
|
export async function readFilesIntoDict(pattern, prefix) {
|
||||||
// Prepend the prefix to the glob pattern
|
// Prepend the prefix to the glob pattern
|
||||||
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
const globPattern = prefix ? path.join(prefix, pattern) : pattern;
|
||||||
const files = await glob(globPattern);
|
const files = await glob(globPattern);
|
||||||
@@ -88,7 +89,7 @@ async function readFilesIntoDict(pattern, prefix) {
|
|||||||
* @param {string} password - The password.
|
* @param {string} password - The password.
|
||||||
* @returns {string|null} - Returns an error message if validation fails, otherwise null.
|
* @returns {string|null} - Returns an error message if validation fails, otherwise null.
|
||||||
*/
|
*/
|
||||||
function validateAuthentication(token, username, password) {
|
export function validateAuthentication(token, username, password) {
|
||||||
if (token) {
|
if (token) {
|
||||||
if (username || password) {
|
if (username || password) {
|
||||||
return "Token is defined along with username and/or password.";
|
return "Token is defined along with username and/or password.";
|
||||||
@@ -110,7 +111,7 @@ function validateAuthentication(token, username, password) {
|
|||||||
/**
|
/**
|
||||||
* Posts code to Screeps server.
|
* Posts code to Screeps server.
|
||||||
*/
|
*/
|
||||||
async function postCode() {
|
export async function postCode() {
|
||||||
const protocol = core.getInput("protocol") || "https";
|
const protocol = core.getInput("protocol") || "https";
|
||||||
const hostname = core.getInput("hostname") || "screeps.com";
|
const hostname = core.getInput("hostname") || "screeps.com";
|
||||||
const port = core.getInput("port") || "443";
|
const port = core.getInput("port") || "443";
|
||||||
@@ -175,14 +176,7 @@ async function postCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (require.main === module) {
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
|
if (process.argv[1] === __filename) {
|
||||||
postCode();
|
postCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
validateAuthentication,
|
|
||||||
replacePlaceholders,
|
|
||||||
postCode,
|
|
||||||
readReplaceAndWriteFiles,
|
|
||||||
readFilesIntoDict,
|
|
||||||
};
|
|
||||||
|
|||||||
32
package-lock.json
generated
32
package-lock.json
generated
@@ -8,7 +8,7 @@
|
|||||||
"name": "screeps-deploy-action",
|
"name": "screeps-deploy-action",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^2.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
"glob": "^13.0.0",
|
"glob": "^13.0.0",
|
||||||
"screeps-api": "^1.7.2"
|
"screeps-api": "^1.7.2"
|
||||||
},
|
},
|
||||||
@@ -19,28 +19,28 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "2.0.3",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-2.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-3.0.0.tgz",
|
||||||
"integrity": "sha512-Od9Thc3T1mQJYddvVPM4QGiLUewdh+3txmDYHHxoNdkqysR1MbCT+rFOtNUxYAz+7+6RIsqipVahY2GJqGPyxA==",
|
"integrity": "sha512-zYt6cz+ivnTmiT/ksRVriMBOiuoUpDCJJlZ5KPl2/FRdvwU3f7MPh9qftvbkXJThragzUZieit2nyHUyw53Seg==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/exec": "^2.0.0",
|
"@actions/exec": "^3.0.0",
|
||||||
"@actions/http-client": "^3.0.2"
|
"@actions/http-client": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/exec": {
|
"node_modules/@actions/exec": {
|
||||||
"version": "2.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-3.0.0.tgz",
|
||||||
"integrity": "sha512-k8ngrX2voJ/RIN6r9xB82NVqKpnMRtxDoiO+g3olkIUpQNqjArXrCQceduQZCQj3P3xm32pChRLqRrtXTlqhIw==",
|
"integrity": "sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/io": "^2.0.0"
|
"@actions/io": "^3.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/http-client": {
|
"node_modules/@actions/http-client": {
|
||||||
"version": "3.0.2",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-3.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-4.0.0.tgz",
|
||||||
"integrity": "sha512-JP38FYYpyqvUsz+Igqlc/JG6YO9PaKuvqjM3iGvaLqFnJ7TFmcLyy2IDrY0bI0qCQug8E9K+elv5ZNfw62ZJzA==",
|
"integrity": "sha512-QuwPsgVMsD6qaPD57GLZi9sqzAZCtiJT8kVBCDpLtxhL5MydQ4gS+DrejtZZPdIYyB1e95uCK9Luyds7ybHI3g==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"tunnel": "^0.0.6",
|
"tunnel": "^0.0.6",
|
||||||
@@ -48,9 +48,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/io": {
|
"node_modules/@actions/io": {
|
||||||
"version": "2.0.0",
|
"version": "3.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/io/-/io-3.0.2.tgz",
|
||||||
"integrity": "sha512-Jv33IN09XLO+0HS79aaODsvIRyduiF7NY/F6LYeK5oeUmrsz7aFdRphQjFoESF4jS7lMauDOttKALcpapVDIAg==",
|
"integrity": "sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@babel/helper-string-parser": {
|
"node_modules/@babel/helper-string-parser": {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"name": "screeps-deploy-action",
|
"name": "screeps-deploy-action",
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"description": "Deploys screeps code to the official game or an pirvate server.",
|
"description": "Deploys screeps code to the official game or an pirvate server.",
|
||||||
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node index.js",
|
"start": "node index.js",
|
||||||
@@ -9,7 +10,7 @@
|
|||||||
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
|
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^2.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
"glob": "^13.0.0",
|
"glob": "^13.0.0",
|
||||||
"screeps-api": "^1.7.2"
|
"screeps-api": "^1.7.2"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user