Starting release for mukulmishra18 PR merge #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Merge | |
run-name: Starting release for ${{ github.actor }} PR merge | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: | |
# Test branch for testing the merge workflow, will be changed to develop | |
- feature/test-automated-release | |
jobs: | |
if_merged: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Read package.json version | |
uses: actions/github-script@v6 | |
id: define-package-json-version | |
with: | |
script: | | |
const { version } = require('./package.json') | |
core.info(`performing a ${{ inputs.release-type }} release for existing version ${version}`) | |
core.setOutput('packageJsonVersion', version) | |
- name: Define release version | |
uses: actions/github-script@v6 | |
id: define-release-version | |
with: | |
script: | | |
const { defineReleaseVersion } = require('./.github/scripts/defineVersion.js') | |
return defineReleaseVersion({core}, "${{ inputs.release-type || 'minor' }}", "${{ inputs.prerelease-label }}", "${{ steps.define-package-json-version.outputs.packageJsonVersion }}" ) | |
- name: Checkout develop | |
uses: actions/checkout@v2 | |
with: | |
# For testing checkout to a temp branch, will be changed to develop | |
ref: feature/test-automated-release | |
token: ${{ secrets.GH_TOKEN }} | |
- name: Bump package.json version | |
run: | | |
git pull | |
RELEASE-VERSION=${{ fromJson(steps.define-release-version.outputs.result).full }} | |
npm version "${RELEASE-VERSION}" | |
- name: Update Changelog | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const { execSync } = require('child_process'); | |
const { updateChangeLog } = require('./.github/scripts/updateChangelog.js') | |
const stableVersion = '${{ fromJson(steps.define-release-version.outputs.result).full }}'.split('-')[0] | |
const releaseDate = new Date().toISOString().split('T')[0] | |
const data = fs.readFileSync('./CHANGELOG.md',{encoding:'utf8', flag:'r'}); | |
core.info(`Updating ${stableVersion} with date ${releaseDate} in Changelog`); | |
const changelogFileContents = updateChangeLog(data, stableVersion, releaseDate); | |
fs.writeFileSync('./CHANGELOG.md', changelogFileContents, 'utf-8'); | |
- name: Push changes | |
uses: actions/github-script@v6 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
script: | | |
const { execSync } = require('child_process'); | |
const fullReleaseVersion = ${{ fromJson(steps.define-release-version.outputs.result).full }}; | |
const { github } = require('@actions/github'); | |
const octokit = github.getOctokit('${{ secrets.GH_TOKEN }}'); | |
core.info(`Pushing changes to branch`); | |
execSync(`git add .`); | |
execSync(`git commit -m "Bump version ${fullReleaseVersion} and update changelog"`); | |
execSync(`git push origin feature/test-automated-release`); | |
- name: Tag and push | |
uses: actions/github-script@v6 | |
# Tag push should happen without a token, otherwise it will not trigger release workflow | |
# DO NOT PUSH TAG FOR TESTING | |
with: | |
script: | | |
const { execSync } = require('child_process'); | |
const fullReleaseVersion = ${{ fromJson(steps.define-release-version.outputs.result).full }} | |
const tag = `v${fullReleaseVersion}`; | |
const message = `Release ${fullReleaseVersion}`; | |
core.info(`Creating tag ${tag} with message ${message}`); | |
execSync(`git config --global user.name 'Automated Release'`); | |
execSync(`git config --global user.email '[email protected]'`); | |
execSync(`git tag -a ${tag} -m "${message}"`); |