https://github.com/zhhaogen/read-properties-action
读取properties文件并输出为变量
https://github.com/zhhaogen/read-properties-action
Last synced: about 2 months ago
JSON representation
读取properties文件并输出为变量
- Host: GitHub
- URL: https://github.com/zhhaogen/read-properties-action
- Owner: zhhaogen
- License: mpl-2.0
- Created: 2024-12-26T12:16:58.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-26T14:20:08.000Z (5 months ago)
- Last Synced: 2024-12-26T14:24:45.163Z (5 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Read Properties Action
读取properties文件并输出为变量## 输入
|名称|类型|是否必须|默认值|描述|
|-|-|-|-|-|
|file|String|否|undefined|properties文件位置,多行文本|
|prefix|String|否|""|输出变量的前缀,多行文本,数量应该与file数量一致|
|configJson|String|否|undefined|配置json|## 例子
### 最简单的
`resources/application.properties`内容如下
```
server.port=8080
```
`test.yml`文件
```
name: Read Properties
run-name: 读取打印properties文件变量
on:
- workflow_dispatch
permissions:
contents: read
jobs:
dump:
runs-on: ubuntu-latest
steps:
- name: 检出代码
uses: actions/checkout@v4
- name: 读取Properties变量
id: readps
uses: zhhaogen/[email protected]
with:
file: resources/application.properties
- name: 打印Properties变量
run: echo ${{ steps.readps.outputs.server.port }}```
期望输出结果
```
8080
```
### 使用前缀`test.yml`文件
```
- name: 读取Properties变量
uses: zhhaogen/[email protected]
id: readps
with:
file: resources/application.properties
prefix: current_
- name: 打印Properties变量
run: echo ${{ steps.readps.outputs.current_server.port }}```
期望输出结果
```
8080
```### 使用多个文件
`resources/application-test.properties`内容如下
```
server.port=9090
```
`test.yml`文件
```
- name: 读取Properties变量
uses: zhhaogen/[email protected]
id: readps
with:
file: |-
resources/application.properties
resources/application-test.properties
prefix: |-
current_
test_
- name: 打印Properties变量
run: echo ${{ steps.readps.outputs.current_server.port }},${{ steps.readps.outputs.test_server.port }}
```
期望输出结果
```
8080,9090
```### 使用configJson
`configJson`实际值为
```
[
{'file':'resources/application.properties','prefix':'current_'},
{'file':'resources/application-test.properties','prefix':'test_'}
]
```
转为json字符串
```
[{"file":"resources/application.properties","prefix":"current_"},{"file":"resources/application-test.properties","prefix":"test_"}]
````test.yml`文件
```
- name: 读取Properties变量
uses: zhhaogen/[email protected]
id: readps
with:
configJson: '[{"file":"resources/application.properties","prefix":"current_"},{"file":"resources/application-test.properties","prefix":"test_"}]'
- name: 打印Properties变量
run: echo ${{ steps.readps.outputs.current_server.port }},${{ steps.readps.outputs.test_server.port }}
```
期望输出结果
```
8080,9090
```