-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yaml
170 lines (152 loc) · 6.75 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Dry-run Renovate
description: 'Dry-run Renovate and output to summary'
inputs:
config-file:
description: 'Renovate config file'
required: true
cache:
description: 'if `true`, cache ~/.npm'
required: false
default: "true"
log-level:
description: 'Renovate log level [trace|debug|info|warn|error|fatal]'
required: false
default: "debug"
log-format:
description: 'Renovate log format [text|json]'
required: false
default: "text"
save-log:
description: 'if `true`, save log file'
required: false
default: "false"
detail-summary:
description: 'if `true`, enclose the output log to the summary in a detail tag.'
required: false
default: "true"
token:
description: 'GitHub token'
required: false
default: ${{ github.token }}
renovate-username:
description: 'Renovate username'
required: false
default: "GitHub Action"
renovate-git-author:
description: 'Renovate git author'
required: false
default: "GitHub Action <action@github.com>"
install-lts-nodejs:
description: 'if `true`, install LTS Node.js. Because Renovate may require more than the default Node.js version of GitHub Actions.'
required: false
default: "true"
runs:
using: "composite"
steps:
- name: Setup
id: setup
shell: bash
run: |
# Get the major version number of Renovate to use for the cache key.
echo "renovate-version=$(npm show renovate version --no-update-notifier | cut -d . -f 1)" >> $GITHUB_OUTPUT
# Create a path to save the Renovate log.
echo "renovate-log=${{ runner.temp }}/renovate-dry-run.log" >> $GITHUB_OUTPUT
# Create a path to save a action summary.
echo "summary=${{ runner.temp }}/summary.md" >> $GITHUB_OUTPUT
# Setup LTS Node.js
# Because Renovate may require more than the default Node.js version of GitHub Actions.
# see: https://github.com/cybozu/renovate-dry-run-action/issues/26
- name: Setup LTS Node.js
if: inputs.install-lts-nodejs == 'true'
uses: actions/setup-node@v4
with:
node-version: lts/*
- uses: actions/cache@v4
if: inputs.cache == 'true'
with:
path: ~/.npm
# Cache Renovate and its dependencies,
# using the major version of Renovate as the cache key because Renovate is updated frequently.
key: npm-renovate-major-v${{ steps.setup.outputs.renovate-version }}
- name: Dry-run Renovate
env:
# By setting `RENOVATE_USERNAME` and `RENOVATE_GIT_AUTHOR`,
# `GITHUB_TOKEN` can be used for the secret requested by Renovate.
# ref: https://zenn.dev/azrsh/articles/renovate-dry-run-ci#%E5%AE%9F%E8%A3%85-2
# Use the `GitHub Action' user to make it explicit that the execution is through GitHub Actions.
# ref: https://github.com/actions/checkout/issues/13
RENOVATE_USERNAME: ${{ inputs.renovate-username }}
RENOVATE_GIT_AUTHOR: ${{ inputs.renovate-git-author }}
RENOVATE_TOKEN: ${{ inputs.token }}
# Set the log level for Renovate.
# ref: https://docs.renovatebot.com/examples/self-hosting/#about-the-log-level-numbers
# Renovate supports specifying log levels in environment variables.
# ref: https://github.com/renovatebot/renovate/issues/8291
LOG_LEVEL: ${{ inputs.log-level }}
# Renovate outputs human readable logs by default;
# by specifying LOG_FORMAT=json, it outputs logs in json format.
# ref: https://docs.renovatebot.com/examples/self-hosting/#logging
# Renovate supports specifying the log format in environment variables.
# ref: https://github.com/renovatebot/renovate/blob/3b72d500983036ec76d33e70a1a177f800321d78/lib/logger/index.ts#L31
LOG_FORMAT: ${{ inputs.log-format }}
# Specify the config file for Renovate.
# ref: https://github.com/renovatebot/renovate/blob/3b72d500983036ec76d33e70a1a177f800321d78/docs/development/configuration.md?plain=1#LL20-L21
RENOVATE_CONFIG_FILE: ${{ inputs.config-file }}
shell: bash
# Description of options
# - `--schedule` : Set to empty to ignore schedule settings.
# - `--require-config=ignored` : Set to ignore the default branch config of the remote repository.
# Without it, the default branch config of the remote repository is used.
# - `--dry-run` : Enable dry-run to avoid creating PRs, auto-merging, and updating the Dependency Dashboard.
run: |
npx renovate \
--schedule= \
--require-config=ignored \
--dry-run ${{ github.repository }} \
| tee ${{ steps.setup.outputs.renovate-log }}
# Create a step summary for multiple steps,
# because the insertion of the `details` tag is controlled by `input`.
# Use `always()` to output a log even if Renovate fails.
# Write the summary to a temporary file first, without outputting directly to `$GITHUB_STEP_SUMMARY`,
# because the `details` tag will not work if the steps are separated.
# see: https://github.com/community/community/discussions/44185
- name: Create step summary [title]
if: always()
shell: bash
run: |
echo "# Renovate dry run log" > ${{ steps.setup.outputs.summary }}
- name: Create step summary [details start tag]
if: always() && inputs.detail-summary == 'true'
shell: bash
run: |
echo "<details>" >> ${{ steps.setup.outputs.summary }}
echo "<summary>detail</summary>" >> ${{ steps.setup.outputs.summary }}
- name: Create step summary [body]
if: always()
shell: bash
run: |
# The top and bottom of the codeblock must be blank lines, so use line breaks to sandwich the codeblock.
echo "" >> ${{ steps.setup.outputs.summary }}
echo '```json' >> ${{ steps.setup.outputs.summary }}
cat ${{ steps.setup.outputs.renovate-log }} >> ${{ steps.setup.outputs.summary }}
echo '```' >> ${{ steps.setup.outputs.summary }}
echo "" >> ${{ steps.setup.outputs.summary }}
- name: Create step summary [details end tag]
if: always() && inputs.detail-summary == 'true'
shell: bash
run: |
echo "</details>" >> ${{ steps.setup.outputs.summary }}
- name: Output to step summary
if: always()
shell: bash
run: |
cat ${{ steps.setup.outputs.summary }} >> $GITHUB_STEP_SUMMARY
# Save the Renovate log to an artifact.
# Use `always()` to save a log even if Renovate fails.
- name: Save log
if: always() && inputs.save-log == 'true'
uses: actions/upload-artifact@v4
with:
name: renovate-dry-run-log
path: |
${{ steps.setup.outputs.renovate-log }}