Code documentation of continuous integration workflow
# workflow name
name: Continuous Integration
# on represent event that trigger the workflow
on:
workflow_dispatch:
inputs:
version:
description: Bump Version # user input field
default: patch #(patch, minor, major)
required: true
changelog:
description: (Optional) Changelog FORMATTED MARKDOWN
default:
required: false
# jobs run parally and any workflow require atleast on job in it
jobs:
release-draft:
runs-on: ubuntu-latest # this part will run on linux env
outputs:
upload_url: ${{ steps.create_release_draft.outputs.upload_url }} #url of draft to upload assets
draft_id: ${{ steps.create_release_draft.outputs.id }} #draft id to publish release
app_version: v${{ env.PACKAGE_VERSION }} #package.json version to print version on builds
commit_hash: ${{ env.COMMIT_HASH }} #commit hash to checkout when required
# Uncomment below code if you want this workflow to triggered by CODE OWNER ONLY
# if: github.actor == github.event.repository.owner.login
# instructional command of each job
steps:
- name: Workflow Authentication #This will check person who triggered the workflow is a collaborator or not
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/collaborators/${{ github.actor }} # <https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-repository-collaborator>
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#checkout master branch
- name: Checkout master
uses: actions/checkout@v2
with:
ref: master #checkout master branch
# configure github account
# use npm to bump version, tag and commit using standard-version package
# save commit_hash as env variable
# push commit and tag
# get app version from package.json
- name: Bump version and push commit with tag
run: |
git config --global user.name "AtiqGauri"
git config --global user.email "[email protected]"
npm install standard-version --prefix Patternscape_GUI/ --no-save
npm run release --prefix Patternscape_GUI/ -- --release-as ${{ github.event.inputs.version }}
echo ::set-env name=COMMIT_HASH::$(git rev-parse --verify HEAD)
git push --follow-tags origin master
echo ::set-env name=PACKAGE_VERSION::$(node -p -e "require('./Patternscape_GUI/package.json').version")
# create a release draft with option changelog and store its url
- name: Create a release draft
id: create_release_draft
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.PACKAGE_VERSION }}
release_name: Patternscape v${{ env.PACKAGE_VERSION }}
body: |
Changelog: [Project Timeline](<https://paper.dropbox.com/doc/Projects-Timeline--A4KNJax_pZMmJHwFv57DRJU~AQ-BoYhgTkFCHQ91an0uF9eg>)
${{ github.event.inputs.changelog }}
draft: true
prerelease: false
# another jon with matrix(means it will be 3 jobs in total)
# set node env and working directories
builds:
needs: release-draft # depend on draft job so we can get upload_url to upload assets
runs-on: ${{ matrix.platform }}
strategy:
matrix:
node-version: [12.x]
platform: [ubuntu-20.04, macos-latest, windows-latest]
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APP_VERSION: ${{ needs.release-draft.outputs.app_version }} # get app version from draft job
defaults:
run:
working-directory: Patternscape_GUI/ #all the run commands gonna run in this directory