From 3e20bc9d41be80b3a95077e1c7df8e6f0f83d6b7 Mon Sep 17 00:00:00 2001 From: Soumya Ranjan Mahunt Date: Wed, 9 Mar 2022 22:23:39 +0530 Subject: [PATCH] ci: setup CI/CD pipeline --- .github/config/config.js | 20 +++ .github/config/package-lock.json | 223 +++++++++++++++++++++++++++ .github/config/package.json | 16 ++ .github/config/pre_changelog_hook.js | 30 ++++ .github/workflows/main.yml | 129 ++++++++++++++++ 5 files changed, 418 insertions(+) create mode 100644 .github/config/config.js create mode 100644 .github/config/package-lock.json create mode 100644 .github/config/package.json create mode 100644 .github/config/pre_changelog_hook.js create mode 100644 .github/workflows/main.yml diff --git a/.github/config/config.js b/.github/config/config.js new file mode 100644 index 0000000..bc7e184 --- /dev/null +++ b/.github/config/config.js @@ -0,0 +1,20 @@ +'use strict' +const config = require('conventional-changelog-conventionalcommits'); + +module.exports = config({ + "types": [ + { type: 'feat', section: '🚀 Features' }, + { type: 'fix', section: '🐛 Fixes' }, + { type: 'perf', section: '🐎 Performance Improvements' }, + { type: 'revert', section: '⏪ Reverts' }, + { type: 'build', section: '🛠 Build System' }, + { type: 'ci', section: '💡 Continuous Integration' }, + { type: 'refactor', section: '🔥 Refactorings' }, + { type: 'doc', section: '📚 Documentation' }, + { type: 'docs', section: '📚 Documentation' }, + { type: 'style', section: '💄 Styles' }, + { type: 'test', section: '✅ Tests' }, + { type: 'wip', hidden: true }, + { type: 'chore', hidden: true }, + ] +}) \ No newline at end of file diff --git a/.github/config/package-lock.json b/.github/config/package-lock.json new file mode 100644 index 0000000..db4aaa5 --- /dev/null +++ b/.github/config/package-lock.json @@ -0,0 +1,223 @@ +{ + "name": "config", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "config", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "@actions/core": "1.6.0", + "conventional-changelog-conventionalcommits": "^4.6.3", + "semver": "^7.3.5" + } + }, + "node_modules/@actions/core": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", + "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", + "dependencies": { + "@actions/http-client": "^1.0.11" + } + }, + "node_modules/@actions/http-client": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", + "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", + "dependencies": { + "tunnel": "0.0.6" + } + }, + "node_modules/array-ify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz", + "integrity": "sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=" + }, + "node_modules/compare-func": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz", + "integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==", + "dependencies": { + "array-ify": "^1.0.0", + "dot-prop": "^5.1.0" + } + }, + "node_modules/conventional-changelog-conventionalcommits": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.6.3.tgz", + "integrity": "sha512-LTTQV4fwOM4oLPad317V/QNQ1FY4Hju5qeBIM1uTHbrnCE+Eg4CdRZ3gO2pUeR+tzWdp80M2j3qFFEDWVqOV4g==", + "dependencies": { + "compare-func": "^2.0.0", + "lodash": "^4.17.15", + "q": "^1.5.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/dot-prop": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", + "dependencies": { + "is-obj": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/q": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", + "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=", + "engines": { + "node": ">=0.6.0", + "teleport": ">=0.2.0" + } + }, + "node_modules/semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + }, + "dependencies": { + "@actions/core": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz", + "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==", + "requires": { + "@actions/http-client": "^1.0.11" + } + }, + "@actions/http-client": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz", + "integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==", + "requires": { + "tunnel": "0.0.6" + } + }, + "array-ify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz", + "integrity": "sha1-nlKHYrSpBmrRY6aWKjZEGOlibs4=" + }, + "compare-func": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/compare-func/-/compare-func-2.0.0.tgz", + "integrity": "sha512-zHig5N+tPWARooBnb0Zx1MFcdfpyJrfTJ3Y5L+IFvUm8rM74hHz66z0gw0x4tijh5CorKkKUCnW82R2vmpeCRA==", + "requires": { + "array-ify": "^1.0.0", + "dot-prop": "^5.1.0" + } + }, + "conventional-changelog-conventionalcommits": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.6.3.tgz", + "integrity": "sha512-LTTQV4fwOM4oLPad317V/QNQ1FY4Hju5qeBIM1uTHbrnCE+Eg4CdRZ3gO2pUeR+tzWdp80M2j3qFFEDWVqOV4g==", + "requires": { + "compare-func": "^2.0.0", + "lodash": "^4.17.15", + "q": "^1.5.1" + } + }, + "dot-prop": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", + "integrity": "sha512-QM8q3zDe58hqUqjraQOmzZ1LIH9SWQJTlEKCH4kJ2oQvLZk7RbQXvtDM2XEq3fwkV9CCvvH4LA0AV+ogFsBM2Q==", + "requires": { + "is-obj": "^2.0.0" + } + }, + "is-obj": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", + "integrity": "sha512-drqDG3cbczxxEJRoOXcOjtdp1J/lyp1mNn0xaznRs8+muBhgQcrnbspox5X5fOw0HnMnbfDzvnEMEtqDEJEo8w==" + }, + "lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "requires": { + "yallist": "^4.0.0" + } + }, + "q": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", + "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=" + }, + "semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + } + }, + "tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==" + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } +} diff --git a/.github/config/package.json b/.github/config/package.json new file mode 100644 index 0000000..7240f7b --- /dev/null +++ b/.github/config/package.json @@ -0,0 +1,16 @@ +{ + "name": "config", + "version": "1.0.0", + "description": "conventional-changelog-action hooks", + "main": "config.js", + "license": "MIT", + "author": { + "name": "Soumya Ranjan Mahunt", + "email": "devsoumyamahunt@gmail.com" + }, + "dependencies": { + "@actions/core": "1.6.0", + "conventional-changelog-conventionalcommits": "^4.6.3", + "semver": "^7.3.5" + } +} diff --git a/.github/config/pre_changelog_hook.js b/.github/config/pre_changelog_hook.js new file mode 100644 index 0000000..614e23e --- /dev/null +++ b/.github/config/pre_changelog_hook.js @@ -0,0 +1,30 @@ +const path = require('path'); +const fs = require('fs'); +const semver = require('semver'); +const core = require('@actions/core'); +const childProcess = require("child_process"); + +exports.preVersionGeneration = (version) => { + const { GITHUB_WORKSPACE } = process.env; + core.info(`Computed version bump: ${version}`); + + const gem_info_file = path.join(GITHUB_WORKSPACE, 'lib/cocoapods-embed-flutter/gem_version.rb'); + const gem_info = `${fs.readFileSync(gem_info_file)}`; + core.info(`Current gem info: ${gem_info}`); + + currentVersion = gem_info.match(/VERSION\s*=\s'(.*)'/)[1]; + core.info(`Current version: ${currentVersion}`); + + if (semver.lt(version, currentVersion)) { version = currentVersion; } + core.info(`Final version: ${version}`); + + const new_gem_info = gem_info.replace(/VERSION\s*=\s*.*/g, `VERSION = '${version}'.freeze`); + core.info(`Updated gem info: ${new_gem_info}`); + fs.writeFileSync(gem_info_file, new_gem_info); + + const launchOption = { cwd: GITHUB_WORKSPACE }; + childProcess.execSync('bundle exec rake demo', launchOption); + return version; +} + +exports.preTagGeneration = (tag) => { } \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9b81db7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,129 @@ +name: CI/CD + +on: + push: + branches: [ main ] + paths-ignore: + - '*.md' + pull_request: + branches: [ main ] + paths-ignore: + - '*.md' + +env: + RUBY_VER: 2.6 + +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + +jobs: + ci: + name: Run Tests + runs-on: ubuntu-latest + outputs: + release: ${{ steps.check_version_bump.outputs.release_type != '' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ env.RUBY_VER }} + + - name: Install dependencies + run: | + bundle config deployment true + bundle install + + - name: Test example app + run: bundle exec rake demo + + - name: Run tests + run: bundle exec rake specs + + - name: Check version bump + id: check_version_bump + uses: mathieudutour/github-tag-action@v6.0 + with: + github_token: ${{ github.token }} + default_bump: false + dry_run: true + + cd: + name: Build and Publish + if: github.event_name == 'push' && needs.ci.outputs.release + needs: ci + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup node + uses: actions/setup-node@v2 + with: + node-version: '17' + + - name: Setup action config + run: npm install + working-directory: .github/config + + # - name: Conventional Changelog Action + # id: conventional_changelog + # uses: TriPSs/conventional-changelog-action@v3 + # with: + # github-token: ${{ github.token }} + # git-message: 'chore(CHANGELOG): update for {version}' + # git-user-name: ${{ github.actor }} + # git-user-email: devsoumyamahunt@gmail.com + # skip-version-file: true + # release-count: 0 + # pre-changelog-generation: '.github/config/pre_changelog_hook.js' + # config-file-path: '.github/config/config.js' + + # - name: Setup Ruby + # if: steps.conventional_changelog.outputs.skipped == 'false' + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: ${{ env.RUBY_VER }} + + # - name: Build gem + # if: steps.conventional_changelog.outputs.skipped == 'false' + # run: gem build *.gemspec + + # - name: Publish to GitHub Package Registry + # if: steps.conventional_changelog.outputs.skipped == 'false' + # run: | + # mkdir -p $HOME/.gem + # touch $HOME/.gem/credentials + # chmod 0600 $HOME/.gem/credentials + # printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials + # gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem + # env: + # GITHUB_TOKEN: ${{ github.token }} + # OWNER: ${{ github.actor }} + + # - name: Publish to RubyGems + # if: steps.conventional_changelog.outputs.skipped == 'false' + # run: | + # mkdir -p $HOME/.gem + # touch $HOME/.gem/credentials + # chmod 0600 $HOME/.gem/credentials + # printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + # gem push *.gem + # env: + # GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }} + + # - name: Create GitHub Release + # if: steps.conventional_changelog.outputs.skipped == 'false' + # uses: ncipollo/release-action@v1 + # with: + # token: ${{ github.token }} + # tag: ${{ steps.conventional_changelog.outputs.tag }} + # body: ${{ steps.conventional_changelog.outputs.changelog }} + # artifacts: '*.gem'