@@ -144,7 +144,60 @@ jobs:
144144 if : ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
145145 uses : remal-github-actions/read-nodejs-package-version@v1
146146
147+ - name : Remove files listed in .releaseignore
148+ if : ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
149+ id : releaseignore
150+ uses : actions/github-script@v8
151+ with :
152+ script : |
153+ const fs = require('fs')
154+ const path = require('path')
155+
156+ const cwdPath = path.resolve(process.cwd())
157+
158+ const releaseIgnorePath = '.releaseignore'
159+ const releaseIgnoreFullPath = path.resolve(cwdPath, releaseIgnorePath)
160+ if (!fs.existsSync(releaseIgnoreFullPath)) {
161+ core.info(`${releaseIgnorePath} file does not exist, skipping removal of files.`)
162+ core.setOutput('skipped', 'true')
163+ return
164+ }
165+
166+ let patternsToIgnore = fs.readFileSync(releaseIgnoreFullPath, 'utf-8')
167+ .split('\n')
168+ .map(line => line.replace(/#.*/, '').trim())
169+ .filter(line => line.length)
170+ .join('\n')
171+ if (!patternsToIgnore.length) {
172+ core.info(`${releaseIgnorePath} file does not have patterns, skipping removal of files.`)
173+ core.setOutput('skipped', 'true')
174+ return
175+ }
176+
177+ const gitDirPath = path.resolve(cwdPath, '.git')
178+
179+ const globber = await glob.create(patternsToIgnore)
180+ const files = await globber.glob()
181+ files
182+ .map(file => path.resolve(cwdPath, file))
183+ .filter(file => file != cwdPath)
184+ .filter(file => file != gitDirPath && !file.startsWith(gitDirPath + path.sep))
185+ .forEach(file => {
186+ core.debug(`Removing: ${file}`)
187+ fs.rmSync(file, { recursive: true, force: true })
188+ })
189+
190+ - name : Prepare release commit
191+ if : ${{github.event_name == 'push' && github.ref == 'refs/heads/main' && !steps.releaseignore.outputs.skipped}}
192+ run : |
193+ RELEASE_BRANCH="release/v${{steps.readVersion.outputs.majorVersion}}"
194+ git switch --force-create "$RELEASE_BRANCH"
195+ git add --all
196+ git commit -m "[skip-ci] Release v${{steps.readVersion.outputs.majorVersion}}" || true
197+ git push --force origin "$RELEASE_BRANCH"
198+
147199 - name : Create tag
200+ if : ${{github.event_name == 'push' && github.ref == 'refs/heads/main'}}
148201 uses : remal-github-actions/create-tag@v2
149202 with :
150203 tagName : ' v${{steps.readVersion.outputs.majorVersion}}'
0 commit comments