|
| 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: cbsecurity |
| 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 CommandBox |
| 35 | + uses: Ortus-Solutions/[email protected] |
| 36 | + with: |
| 37 | + forgeboxAPIKey: ${{ secrets.FORGEBOX_TOKEN }} |
| 38 | + |
| 39 | + - name: "Setup Environment Variables For Build Process" |
| 40 | + id: current_version |
| 41 | + run: | |
| 42 | + echo "VERSION=`cat box.json | jq '.version' -r`" >> $GITHUB_ENV |
| 43 | + |
| 44 | + # master or snapshot |
| 45 | + echo "Github Ref is $GITHUB_REF" |
| 46 | + echo "BRANCH=master" >> $GITHUB_ENV |
| 47 | + if [ $GITHUB_REF == 'refs/heads/development' ] |
| 48 | + then |
| 49 | + echo "BRANCH=development" >> $GITHUB_ENV |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Update changelog [unreleased] with latest version |
| 53 | + uses: thomaseizinger/[email protected] |
| 54 | + if: env.SNAPSHOT == 'false' |
| 55 | + with: |
| 56 | + changelogPath: ./changelog.md |
| 57 | + tag: v${{ env.VERSION }} |
| 58 | + |
| 59 | + - name: Build ${{ env.MODULE_ID }} |
| 60 | + run: | |
| 61 | + npm install -g markdownlint-cli |
| 62 | + markdownlint changelog.md --fix |
| 63 | + box install commandbox-docbox |
| 64 | + box task run taskfile=build/Build target=run :version=${{ env.VERSION }} :projectName=${{ env.MODULE_ID }} :buildID=${{ github.run_number }} :branch=${{ env.BRANCH }} |
| 65 | +
|
| 66 | + - name: Commit Changelog To Master |
| 67 | + |
| 68 | + if: env.SNAPSHOT == 'false' |
| 69 | + with: |
| 70 | + author_name: Github Actions |
| 71 | + |
| 72 | + message: 'Finalized changelog for v${{ env.VERSION }}' |
| 73 | + add: changelog.md |
| 74 | + |
| 75 | + - name: Tag Version |
| 76 | + |
| 77 | + if: env.SNAPSHOT == 'false' |
| 78 | + with: |
| 79 | + tag: "v${{ env.VERSION }}" |
| 80 | + force_push_tag: true |
| 81 | + message: "Latest Release v${{ env.VERSION }}" |
| 82 | + |
| 83 | + - name: Upload Build Artifacts |
| 84 | + if: success() |
| 85 | + uses: actions/upload-artifact@v3 |
| 86 | + with: |
| 87 | + name: ${{ env.MODULE_ID }} |
| 88 | + path: | |
| 89 | + .artifacts/**/* |
| 90 | + changelog.md |
| 91 | +
|
| 92 | + - name: Upload Binaries to S3 |
| 93 | + uses: jakejarvis/s3-sync-action@master |
| 94 | + with: |
| 95 | + args: --acl public-read |
| 96 | + env: |
| 97 | + AWS_S3_BUCKET: "downloads.ortussolutions.com" |
| 98 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} |
| 99 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_SECRET }} |
| 100 | + SOURCE_DIR: ".artifacts/${{ env.MODULE_ID }}" |
| 101 | + DEST_DIR: "ortussolutions/coldbox-modules/${{ env.MODULE_ID }}" |
| 102 | + |
| 103 | + - name: Upload API Docs to S3 |
| 104 | + uses: jakejarvis/s3-sync-action@master |
| 105 | + with: |
| 106 | + args: --acl public-read |
| 107 | + env: |
| 108 | + AWS_S3_BUCKET: "apidocs.ortussolutions.com" |
| 109 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} |
| 110 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_SECRET }} |
| 111 | + SOURCE_DIR: ".tmp/apidocs" |
| 112 | + DEST_DIR: "coldbox-modules/${{ env.MODULE_ID }}/${{ env.VERSION }}" |
| 113 | + |
| 114 | + - name: Publish To ForgeBox |
| 115 | + run: | |
| 116 | + cd .tmp/${{ env.MODULE_ID }} |
| 117 | + cat box.json |
| 118 | + box forgebox publish --force |
| 119 | +
|
| 120 | + - name: Create Github Release |
| 121 | + |
| 122 | + continue-on-error: true |
| 123 | + if: env.SNAPSHOT == 'false' |
| 124 | + with: |
| 125 | + title: ${{ env.VERSION }} |
| 126 | + changelog: changelog.md |
| 127 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + ref: refs/tags/v${{ env.VERSION }} |
| 129 | + |
| 130 | + ########################################################################################## |
| 131 | + # Prep Next Release |
| 132 | + ########################################################################################## |
| 133 | + prep_next_release: |
| 134 | + name: Prep Next Release |
| 135 | + if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' |
| 136 | + runs-on: ubuntu-20.04 |
| 137 | + needs: [ build ] |
| 138 | + steps: |
| 139 | + # Checkout development |
| 140 | + - name: Checkout Repository |
| 141 | + uses: actions/checkout@v3 |
| 142 | + with: |
| 143 | + ref: development |
| 144 | + |
| 145 | + - name: Setup CommandBox |
| 146 | + uses: Ortus-Solutions/[email protected] |
| 147 | + with: |
| 148 | + forgeboxAPIKey: ${{ secrets.FORGEBOX_TOKEN }} |
| 149 | + |
| 150 | + - name: Download build artifacts |
| 151 | + uses: actions/download-artifact@v2 |
| 152 | + with: |
| 153 | + name: ${{ env.MODULE_ID }} |
| 154 | + path: .tmp |
| 155 | + |
| 156 | + # Copy the changelog to the development branch |
| 157 | + - name: Copy Changelog |
| 158 | + run: | |
| 159 | + cp .tmp/changelog.md changelog.md |
| 160 | +
|
| 161 | + # Bump to next version |
| 162 | + - name: Bump Version |
| 163 | + run: | |
| 164 | + box bump --minor --!TagVersion |
| 165 | +
|
| 166 | + # Commit it back to development |
| 167 | + - name: Commit Version Bump |
| 168 | + |
| 169 | + with: |
| 170 | + author_name: Github Actions |
| 171 | + |
| 172 | + message: 'Version bump' |
| 173 | + add: | |
| 174 | + box.json |
| 175 | + changelog.md |
0 commit comments