|
| 1 | +name: Build a Release |
| 2 | + |
| 3 | +on: |
| 4 | + # If you push to master|main this will trigger a stable release |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + - main |
| 9 | + |
| 10 | + # Reusable workflow : Usually called by a `snapshot` workflow |
| 11 | + workflow_call: |
| 12 | + inputs: |
| 13 | + snapshot: |
| 14 | + description: 'Is this a snapshot build?' |
| 15 | + required: false |
| 16 | + default: false |
| 17 | + type: boolean |
| 18 | + |
| 19 | +env: |
| 20 | + MODULE_ID: cbdebugger |
| 21 | + SNAPSHOT: ${{ inputs.snapshot || false }} |
| 22 | + |
| 23 | +jobs: |
| 24 | + ########################################################################################## |
| 25 | + # Build & Publish |
| 26 | + ########################################################################################## |
| 27 | + build: |
| 28 | + name: Build & Publish |
| 29 | + runs-on: ubuntu-20.04 |
| 30 | + steps: |
| 31 | + - name: Checkout Repository |
| 32 | + uses: actions/checkout@v3 |
| 33 | + |
| 34 | + - name: Setup nodejs |
| 35 | + uses: actions/setup-node@v2 |
| 36 | + with: |
| 37 | + node-version: 16.x |
| 38 | + |
| 39 | + - name: Setup CommandBox |
| 40 | + uses: Ortus-Solutions/[email protected] |
| 41 | + with: |
| 42 | + forgeboxAPIKey: ${{ secrets.FORGEBOX_TOKEN }} |
| 43 | + |
| 44 | + - name: "Setup Environment Variables For Build Process" |
| 45 | + id: current_version |
| 46 | + run: | |
| 47 | + echo "VERSION=`cat box.json | jq '.version' -r`" >> $GITHUB_ENV |
| 48 | + |
| 49 | + # master or snapshot |
| 50 | + echo "Github Ref is $GITHUB_REF" |
| 51 | + echo "BRANCH=master" >> $GITHUB_ENV |
| 52 | + if [ $GITHUB_REF == 'refs/heads/development' ] |
| 53 | + then |
| 54 | + echo "BRANCH=development" >> $GITHUB_ENV |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Update changelog [unreleased] with latest version |
| 58 | + uses: thomaseizinger/[email protected] |
| 59 | + if: env.SNAPSHOT == 'false' |
| 60 | + with: |
| 61 | + changelogPath: ./changelog.md |
| 62 | + tag: v${{ env.VERSION }} |
| 63 | + |
| 64 | + - name: Build ${{ env.MODULE_ID }} |
| 65 | + run: | |
| 66 | + npm i npm@latest -g |
| 67 | + npm install |
| 68 | + npm run prod |
| 69 | + rm -Rf node_modules |
| 70 | + box install commandbox-docbox |
| 71 | + box task run taskfile=build/Build target=run :version=${{ env.VERSION }} :projectName=${{ env.MODULE_ID }} :buildID=${{ github.run_number }} :branch=${{ env.BRANCH }} |
| 72 | +
|
| 73 | + - name: Commit Changelog To Master |
| 74 | + |
| 75 | + if: env.SNAPSHOT == 'false' |
| 76 | + with: |
| 77 | + author_name: Github Actions |
| 78 | + |
| 79 | + message: 'Finalized changelog for v${{ env.VERSION }}' |
| 80 | + add: changelog.md |
| 81 | + |
| 82 | + - name: Tag Version |
| 83 | + |
| 84 | + if: env.SNAPSHOT == 'false' |
| 85 | + with: |
| 86 | + tag: "v${{ env.VERSION }}" |
| 87 | + force_push_tag: true |
| 88 | + message: "Latest Release v${{ env.VERSION }}" |
| 89 | + |
| 90 | + - name: Upload Build Artifacts |
| 91 | + if: success() |
| 92 | + uses: actions/upload-artifact@v3 |
| 93 | + with: |
| 94 | + name: ${{ env.MODULE_ID }} |
| 95 | + path: | |
| 96 | + .artifacts/**/* |
| 97 | + changelog.md |
| 98 | +
|
| 99 | + - name: Publish To ForgeBox |
| 100 | + run: | |
| 101 | + cd .tmp/${{ env.MODULE_ID }} && box forgebox publish --force |
| 102 | +
|
| 103 | + - name: Create Github Release |
| 104 | + |
| 105 | + continue-on-error: true |
| 106 | + if: env.SNAPSHOT == 'false' |
| 107 | + with: |
| 108 | + title: ${{ env.VERSION }} |
| 109 | + changelog: changelog.md |
| 110 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + ref: refs/tags/v${{ env.VERSION }} |
| 112 | + |
| 113 | + ########################################################################################## |
| 114 | + # Prep Next Release |
| 115 | + ########################################################################################## |
| 116 | + prep_next_release: |
| 117 | + name: Prep Next Release |
| 118 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 119 | + runs-on: ubuntu-20.04 |
| 120 | + needs: [ build ] |
| 121 | + steps: |
| 122 | + # Checkout development |
| 123 | + - name: Checkout Repository |
| 124 | + uses: actions/checkout@v3 |
| 125 | + with: |
| 126 | + ref: development |
| 127 | + |
| 128 | + - name: Setup CommandBox |
| 129 | + uses: Ortus-Solutions/[email protected] |
| 130 | + with: |
| 131 | + forgeboxAPIKey: ${{ secrets.FORGEBOX_TOKEN }} |
| 132 | + |
| 133 | + - name: Download build artifacts |
| 134 | + uses: actions/download-artifact@v2 |
| 135 | + with: |
| 136 | + name: ${{ env.MODULE_ID }} |
| 137 | + path: .tmp |
| 138 | + |
| 139 | + # Copy the changelog to the development branch |
| 140 | + - name: Copy Changelog |
| 141 | + run: | |
| 142 | + cp .tmp/changelog.md changelog.md |
| 143 | +
|
| 144 | + # Bump to next version |
| 145 | + - name: Bump Version |
| 146 | + run: | |
| 147 | + box bump --minor --!TagVersion |
| 148 | +
|
| 149 | + # Commit it back to development |
| 150 | + - name: Commit Version Bump |
| 151 | + |
| 152 | + with: |
| 153 | + author_name: Github Actions |
| 154 | + |
| 155 | + message: 'Version bump' |
| 156 | + add: | |
| 157 | + box.json |
| 158 | + changelog.md |
0 commit comments