|
| 1 | +name: Bundle Webapp and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'future3/main' |
| 7 | + - 'future3/develop' |
| 8 | + |
| 9 | +jobs: |
| 10 | + |
| 11 | + check: |
| 12 | + if: ${{ github.repository_owner == 'MiczFlor' }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + outputs: |
| 16 | + tag_name: ${{ steps.vars.outputs.tag_name }} |
| 17 | + release_type: ${{ steps.vars.outputs.release_type }} |
| 18 | + check_abort: ${{ steps.vars.outputs.check_abort }} |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Set Output vars |
| 24 | + id: vars |
| 25 | + env: |
| 26 | + BRANCH_NAME: ${{ github.ref_name }} |
| 27 | + run: | |
| 28 | + # Official SemVer Regex definition |
| 29 | + # https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string |
| 30 | + # Needed changes to the regex: |
| 31 | + # - '?:' capture command needed to be removed as it wasn't working in shell |
| 32 | + # - '\d' had to be replaced with [0-9] |
| 33 | + # |
| 34 | + # Release versions like 1.0.0, 3.5.0, 100.4.50000+metadata |
| 35 | + REGEX_VERSION_RELEASE="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$" |
| 36 | + # |
| 37 | + # Prerelease versions like 1.0.0-alpha, 3.5.0-whatsoever.12, 100.4.50000-identifier.12+metadata |
| 38 | + REGEX_VERSION_PRERELEASE="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$" |
| 39 | +
|
| 40 | +
|
| 41 | + # Get the version and calculate release type |
| 42 | + VERSION=$(python ./src/jukebox/jukebox/version.py) |
| 43 | + if echo "$VERSION" | grep -qoE "$REGEX_VERSION_RELEASE" ; then |
| 44 | + RELEASE_TYPE=release |
| 45 | + elif echo "$VERSION" | grep -qoE "$REGEX_VERSION_PRERELEASE" ; then |
| 46 | + RELEASE_TYPE=prerelease |
| 47 | + else |
| 48 | + RELEASE_TYPE=none |
| 49 | + fi |
| 50 | +
|
| 51 | + if [ "$BRANCH_NAME" == 'future3/main' -a "$RELEASE_TYPE" == 'release' ] || [ "$BRANCH_NAME" == 'future3/develop' -a "$RELEASE_TYPE" == 'prerelease' ] ; then |
| 52 | + CHECK_ABORT=false |
| 53 | + else |
| 54 | + echo "::notice title=Abort due to not matching ${RELEASE_TYPE} version for branch!::'${VERSION}' on '${BRANCH_NAME}'" |
| 55 | + CHECK_ABORT=true |
| 56 | + fi |
| 57 | +
|
| 58 | + echo "::group::Output values" |
| 59 | + echo "Version: ${VERSION}" |
| 60 | + echo "RELEASE_TYPE: ${RELEASE_TYPE}" |
| 61 | + echo "BRANCH_NAME: ${BRANCH_NAME}" |
| 62 | + echo "CHECK_ABORT: ${CHECK_ABORT}" |
| 63 | +
|
| 64 | + echo "tag_name=v${VERSION}" >> $GITHUB_OUTPUT |
| 65 | + echo "release_type=${RELEASE_TYPE}" >> $GITHUB_OUTPUT |
| 66 | + echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT |
| 67 | + echo "check_abort=${CHECK_ABORT}" >> $GITHUB_OUTPUT |
| 68 | + echo "::endgroup::" |
| 69 | +
|
| 70 | + build: |
| 71 | + needs: [check] |
| 72 | + if: ${{ needs.check.outputs.check_abort == 'false' }} |
| 73 | + runs-on: ubuntu-latest |
| 74 | + |
| 75 | + env: |
| 76 | + WEBAPP_ROOT_PATH: ./src/webapp |
| 77 | + |
| 78 | + outputs: |
| 79 | + tag_name: ${{ needs.check.outputs.tag_name }} |
| 80 | + release_type: ${{ needs.check.outputs.release_type }} |
| 81 | + commit_sha: ${{ steps.vars.outputs.commit_sha }} |
| 82 | + webapp_bundle_name: ${{ steps.vars.outputs.webapp_bundle_name }} |
| 83 | + webapp_bundle_name_latest: ${{ steps.vars.outputs.webapp_bundle_name_latest }} |
| 84 | + |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v3 |
| 87 | + |
| 88 | + - name: Set Output vars |
| 89 | + id: vars |
| 90 | + env: |
| 91 | + COMMIT_SHA: ${{ github.sha }} |
| 92 | + run: | |
| 93 | + echo "commit_sha=${COMMIT_SHA}" >> $GITHUB_OUTPUT |
| 94 | + echo "webapp_bundle_name=webapp-build-${COMMIT_SHA:0:10}.tar.gz" >> $GITHUB_OUTPUT |
| 95 | + echo "webapp_bundle_name_latest=webapp-build-latest.tar.gz" >> $GITHUB_OUTPUT |
| 96 | +
|
| 97 | + - name: Setup Node.js 20.x |
| 98 | + uses: actions/setup-node@v3 |
| 99 | + with: |
| 100 | + node-version: 20.x |
| 101 | + - name: npm install |
| 102 | + working-directory: ${{ env.WEBAPP_ROOT_PATH }} |
| 103 | + run: npm install |
| 104 | + - name: npm build |
| 105 | + working-directory: ${{ env.WEBAPP_ROOT_PATH }} |
| 106 | + env: |
| 107 | + CI: false |
| 108 | + run: npm run build |
| 109 | + |
| 110 | + - name: Create Bundle |
| 111 | + working-directory: ${{ env.WEBAPP_ROOT_PATH }} |
| 112 | + run: | |
| 113 | + tar -czvf ${{ steps.vars.outputs.webapp_bundle_name }} build |
| 114 | +
|
| 115 | + - name: Artifact Upload |
| 116 | + uses: actions/upload-artifact@v3 |
| 117 | + with: |
| 118 | + name: ${{ steps.vars.outputs.webapp_bundle_name }} |
| 119 | + path: ${{ env.WEBAPP_ROOT_PATH }}/${{ steps.vars.outputs.webapp_bundle_name }} |
| 120 | + retention-days: 5 |
| 121 | + |
| 122 | + release: |
| 123 | + needs: [build] |
| 124 | + runs-on: ubuntu-latest |
| 125 | + |
| 126 | + concurrency: |
| 127 | + group: ${{ needs.build.outputs.tag_name }} |
| 128 | + |
| 129 | + permissions: |
| 130 | + contents: write |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Artifact Download |
| 134 | + uses: actions/download-artifact@v3 |
| 135 | + with: |
| 136 | + name: ${{ needs.build.outputs.webapp_bundle_name }} |
| 137 | + |
| 138 | + - name: Create Release |
| 139 | + uses: ncipollo/release-action@v1 |
| 140 | + with: |
| 141 | + commit: ${{ needs.build.outputs.commit_sha }} |
| 142 | + tag: ${{ needs.build.outputs.tag_name }} |
| 143 | + body: "Automated Release for ${{ needs.build.outputs.tag_name }}" |
| 144 | + makeLatest: 'false' |
| 145 | + prerelease: ${{ needs.build.outputs.release_type == 'prerelease' }} |
| 146 | + generateReleaseNotes: ${{ needs.build.outputs.release_type == 'release' }} |
| 147 | + skipIfReleaseExists: false |
| 148 | + allowUpdates: true |
| 149 | + removeArtifacts: false |
| 150 | + replacesArtifacts: false |
| 151 | + omitBodyDuringUpdate: true |
| 152 | + omitNameDuringUpdate: true |
| 153 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 154 | + |
| 155 | + - name: Get Release by tag |
| 156 | + id: get_release |
| 157 | + uses: joutvhu/get-release@v1 |
| 158 | + env: |
| 159 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 160 | + with: |
| 161 | + tag_name: ${{ needs.build.outputs.tag_name }} |
| 162 | + |
| 163 | + - name: Upload Release Asset |
| 164 | + uses: shogo82148/actions-upload-release-asset@v1 |
| 165 | + env: |
| 166 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + with: |
| 168 | + upload_url: ${{ steps.get_release.outputs.upload_url }} |
| 169 | + asset_name: ${{ needs.build.outputs.webapp_bundle_name }} |
| 170 | + asset_path: ${{ needs.build.outputs.webapp_bundle_name }} |
| 171 | + asset_content_type: application/gzip |
| 172 | + overwrite: true |
| 173 | + |
| 174 | + - name: Upload Release Asset as Latest |
| 175 | + uses: shogo82148/actions-upload-release-asset@v1 |
| 176 | + env: |
| 177 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 178 | + with: |
| 179 | + upload_url: ${{ steps.get_release.outputs.upload_url }} |
| 180 | + asset_name: ${{ needs.build.outputs.webapp_bundle_name_latest }} |
| 181 | + asset_path: ${{ needs.build.outputs.webapp_bundle_name }} |
| 182 | + asset_content_type: application/gzip |
| 183 | + overwrite: true |
0 commit comments