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