Skip to content

Commit afa4ad4

Browse files
committed
Update required fields and add branch push logging
Signed-off-by: Frank Jogeleit <frank.jogeleit@web.de>
1 parent 7600af2 commit afa4ad4

File tree

9 files changed

+77
-47
lines changed

9 files changed

+77
-47
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,10 @@ jobs:
8484
8585
|Argument | Description | Default |
8686
|------------|---------------------------------------------------------------------------------|---------------------|
87-
|valueFile | relative path from the Workspace Directory | _required_ Field |
88-
|propertyPath| PropertyPath for the new value, JSONPath supported | _required_ Field |
89-
|value | New value for the related PropertyPath | _required_ Field |
87+
|valueFile | relative path from the Workspace Directory | _required_ Field if `changes` is not used |
88+
|propertyPath| PropertyPath for the new value, JSONPath supported | _required_ Field if `changes` is not used |
89+
|value | New value for the related PropertyPath | _required_ Field if `changes` is not used |
9090
|changes | Configure changes on multiple values and/or multiple files. Expects all changes as JSON, supported formats are `{"filepath":{"propertyPath":"value"}}` and `{"propertyPath":"value"}`. If you use the second format, it uses the filepath provided from the `valueFile` intput. ||
91-
|labels | Comma separated list of labels, e.g. "feature, yaml-updates" | 'yaml-updates' |
9291
|updateFile | **(deprected)** the updated content will be written into the actual file by default | `false` |
9392
|workDir | Relative location of the configured `repository` | . | |
9493
|format | Specify the used format parser of your file. WIll be guessed by file extension if not provided and uses YAML as fallback. Supports `YAML` and `JSON` ||
@@ -111,6 +110,7 @@ Determine the behavior for none existing properties or array elements.
111110
|----------------|-------------------------------------------------------------------------------------------------------------|------------------------|
112111
|commitChange | Commit the change to __branch__ with the given __message__ | `true` |
113112
|message | Commit message for the changed YAML file | '' |
113+
|labels | Comma separated list of labels, e.g. "feature, yaml-updates" | 'yaml-updates' |
114114
|createPR | Create a PR from __branch__ to __targetBranch__. Use 'true' to enable it | `true` |
115115
|title | Custom title for the created Pull Request | 'Merge: {{message}}' |
116116
|description | Custom description for the created Pull Request | '' |

action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ description: 'Update the property of an existing YAML File'
33
author: 'Frank Jogeleit <frank.jogeleit@web.de>'
44
inputs:
55
valueFile:
6-
required: true
6+
required: false
77
description: 'YAML file which should be updated'
88
propertyPath:
9-
required: true
9+
required: false
1010
description: 'Property Path - valid jsonPath expression'
1111
value:
12-
required: true
12+
required: false
1313
description: 'New property value'
1414
noCompatMode:
1515
required: false

dist/index.js

Lines changed: 34 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "typescript-action",
3-
"version": "0.8.0",
2+
"name": "yaml-update-action",
3+
"version": "0.12.2",
44
"private": true,
5-
"description": "TypeScript template action",
5+
"description": "Update YAML property with dynamic values",
66
"main": "lib/main.js",
77
"scripts": {
88
"build": "tsc",

src/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export async function gitProcessing(
145145
actions.debug(JSON.stringify({createdCommit: newCommitSha}))
146146
actions.setOutput('commit', newCommitSha)
147147

148-
await updateBranch(octokit, owner, repo, branch, newCommitSha)
148+
await updateBranch(octokit, owner, repo, branch, newCommitSha, actions)
149149

150150
actions.debug(`Complete`)
151151
}

src/git-commands.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {Octokit} from '@octokit/rest'
2+
import {Actions} from './github-actions'
23
import {Committer, ChangedFile} from './types'
34

45
export type GitCreateTreeParamsTree = {
@@ -116,21 +117,32 @@ export const createNewCommit = async (
116117
return data.sha
117118
}
118119

119-
export const updateBranch = async (octo: Octokit, owner: string, repo: string, branch: string, commitSha: string): Promise<void> => {
120+
export const updateBranch = async (
121+
octo: Octokit,
122+
owner: string,
123+
repo: string,
124+
branch: string,
125+
commitSha: string,
126+
actions: Actions
127+
): Promise<void> => {
120128
try {
121129
await octo.git.updateRef({
122130
owner,
123131
repo,
124132
ref: `heads/${branch}`,
125133
sha: commitSha
126134
})
127-
} catch (e) {
128-
await octo.git.createRef({
129-
owner,
130-
repo,
131-
ref: `refs/heads/${branch}`,
132-
sha: commitSha
133-
})
135+
} catch (error) {
136+
actions.info(`update branch ${branch} failed (${error}), fallback to create branch`)
137+
138+
await octo.git
139+
.createRef({
140+
owner,
141+
repo,
142+
ref: `refs/heads/${branch}`,
143+
sha: commitSha
144+
})
145+
.catch(e => actions.setFailed(`failed to create branch: ${e}`))
134146
}
135147
}
136148

src/options.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class GitHubOptions implements Options {
148148
}
149149

150150
get changes(): Changes {
151-
const changes: Changes = {}
151+
let changes: Changes = {}
152152
if (this.valueFile && this.propertyPath) {
153153
let value: string | number | boolean = this.value
154154

@@ -163,7 +163,12 @@ export class GitHubOptions implements Options {
163163
}
164164
}
165165

166-
return parseChanges(changes, this.valueFile, core.getInput('changes'))
166+
changes = parseChanges(changes, this.valueFile, core.getInput('changes'))
167+
if (Object.keys(changes).length === 0) {
168+
core.setFailed('No changes to update detected')
169+
}
170+
171+
return changes
167172
}
168173

169174
get method(): Method {

0 commit comments

Comments
 (0)