Google Cloud SDK 安装与配置 GitHub Action 教程
1. 项目目录结构及介绍
.
├── dist/
├── src/
├── tests/
├── .gitignore
├── .prettierrc.js
├── CHANGELOG.md
├── CODEOWNERS
├── LICENSE
├── README.md
├── action.yml
├── eslint.config.mjs
├── package-lock.json
├── package.json
└── tsconfig.json
目录结构介绍
- dist/: 存放编译后的文件。
- src/: 存放源代码文件。
- tests/: 存放测试文件。
- .gitignore: Git 忽略文件配置。
- .prettierrc.js: Prettier 代码格式化配置文件。
- CHANGELOG.md: 项目更新日志。
- CODEOWNERS: 代码所有者配置文件。
- LICENSE: 项目许可证文件。
- README.md: 项目说明文档。
- action.yml: GitHub Action 配置文件。
- eslint.config.mjs: ESLint 配置文件。
- package-lock.json: npm 包锁定文件。
- package.json: npm 包管理文件。
- tsconfig.json: TypeScript 配置文件。
2. 项目的启动文件介绍
项目的启动文件是 action.yml
,这是一个 GitHub Action 的配置文件。它定义了 Action 的输入、输出、运行环境等信息。
action.yml
文件内容
name: 'Setup Google Cloud SDK'
description: 'A GitHub Action for installing and configuring the gcloud CLI'
inputs:
version:
description: 'A string representing the version or version constraint of the Cloud SDK (gcloud) to install'
default: 'latest'
project_id:
description: 'ID of the Google Cloud project'
install_components:
description: 'List of additional gcloud components to install'
skip_install:
description: 'Skip installation of gcloud and use the system-supplied version instead'
outputs:
version:
description: 'Version of gcloud that was installed'
runs:
using: 'node20'
main: 'dist/index.js'
启动文件介绍
- name: Action 的名称。
- description: Action 的描述。
- inputs: 定义了 Action 的输入参数,如
version
、project_id
等。 - outputs: 定义了 Action 的输出参数,如
version
。 - runs: 定义了 Action 的运行环境及主文件路径。
3. 项目的配置文件介绍
.prettierrc.js
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 80,
tabWidth: 2,
};
tsconfig.json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.spec.ts"]
}
eslint.config.mjs
export default [
{
files: ['**/*.js', '**/*.mjs', '**/*.jsx', '**/*.ts', '**/*.tsx'],
rules: {
'no-unused-vars': 'error',
'no-console': 'warn',
},
},
];
配置文件介绍
- .prettierrc.js: 配置代码格式化工具 Prettier,定义了代码风格规则。
- tsconfig.json: 配置 TypeScript 编译选项,定义了编译目标、模块系统、严格模式等。
- eslint.config.mjs: 配置 ESLint,定义了代码检查规则。
通过以上配置文件,项目可以确保代码风格一致、编译正确、代码质量高。