|
| 1 | +name: Build and Deploy Diagnostic Report |
| 2 | + |
| 3 | +env: |
| 4 | + APP_NAME: diagnostic-report |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: |
| 8 | + push: |
| 9 | + branches: |
| 10 | + - main |
| 11 | + - '20[1-9][0-9]_R[1-9]' |
| 12 | + - staging/* |
| 13 | + tags: |
| 14 | + - 'v*' |
| 15 | + pull_request: |
| 16 | + branches: |
| 17 | + - main |
| 18 | + - '20[1-9][0-9]_R[1-9]' |
| 19 | + |
| 20 | +jobs: |
| 21 | + identify_version: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + app-version: ${{ steps.set_version.outputs.version }} |
| 25 | + can-create-release: ${{ steps.set_version.outputs.can_create_release}} |
| 26 | + steps: |
| 27 | + - name: Checkout code repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + - name: Set app version |
| 30 | + id: set_version |
| 31 | + run: | |
| 32 | + # Regex to match semantic versioning (from semver.org) |
| 33 | + # Regex will match valid version number https://regex101.com/r/jPSdnV/1 |
| 34 | + regex='^(v|)((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-]+)*))?)$' |
| 35 | + app_version="" |
| 36 | + create_release=false |
| 37 | + latest_released_tag=$(curl "https://api.github.com/repos/${{github.repository}}/releases/latest" | jq -r .tag_name) |
| 38 | +
|
| 39 | + if [[ "${{github.ref_type}}" == "tag" ]]; then |
| 40 | + pushed_tag="${{github.ref_name}}" |
| 41 | + if [[ "$pushed_tag" =~ $regex ]]; then |
| 42 | + app_version="${BASH_REMATCH[2]}" |
| 43 | + if [[ "$latest_released_tag" =~ $regex ]]; then |
| 44 | + IFS='.' read -r major minor patch <<< "${BASH_REMATCH[2]}" |
| 45 | + next_patch="$major.$minor.$((patch + 1))" |
| 46 | + next_minor="$major.$((minor + 1)).0" |
| 47 | + next_major="$((major + 1)).0.0" |
| 48 | + if [[ "$app_version" == "$next_patch" || "$app_version" == "$next_minor" || "$app_version" == "$next_major" ]]; then |
| 49 | + create_release=true |
| 50 | + else |
| 51 | + echo "Valid tag, but invalid version incrementation, release will NOT be created" |
| 52 | + fi |
| 53 | + else |
| 54 | + echo "Invalid relesed version, skip incrementation validation! Release will be created" |
| 55 | + create_release=true |
| 56 | + fi |
| 57 | + else |
| 58 | + echo "Invalid tag format, release will NOT be created" |
| 59 | + app_version=0.0.1+${{ github.sha }} |
| 60 | + fi |
| 61 | + else |
| 62 | + if [[ "$latest_released_tag" =~ $regex ]]; then |
| 63 | + app_version=${BASH_REMATCH[2]}+${{ github.sha }} |
| 64 | + else |
| 65 | + echo "Invalid relesed version. Setting default version" |
| 66 | + app_version=0.0.1+${{ github.sha }} |
| 67 | + fi |
| 68 | + fi |
| 69 | +
|
| 70 | + echo "Version to use $app_version" |
| 71 | + echo "version=$app_version" >> "$GITHUB_OUTPUT" |
| 72 | + echo "can_create_release=$create_release" >> "$GITHUB_OUTPUT" |
| 73 | + build_and_deploy_for_kuiper: |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: identify_version |
| 76 | + env: |
| 77 | + CONTAINER_BASE_NAME: kuiper-container-basic |
| 78 | + strategy: |
| 79 | + fail-fast: false |
| 80 | + matrix: |
| 81 | + include: |
| 82 | + - docker_image: aandrisa/kuiper_basic_64:latest |
| 83 | + image_arch: linux/arm64 |
| 84 | + architecture: arm64 |
| 85 | + - docker_image: aandrisa/kuiper_basic_32:latest |
| 86 | + image_arch: linux/arm/v7 |
| 87 | + architecture: armhf |
| 88 | + steps: |
| 89 | + - name: Checkout code repository |
| 90 | + uses: actions/checkout@v4 |
| 91 | + with: |
| 92 | + path: ${{env.APP_NAME}} |
| 93 | + |
| 94 | + - name: Set up QEMU |
| 95 | + uses: docker/setup-qemu-action@v3 |
| 96 | + |
| 97 | + - name: Start persistent container |
| 98 | + run: | |
| 99 | + docker run -d \ |
| 100 | + --platform ${{matrix.image_arch}} \ |
| 101 | + --name ${{env.CONTAINER_BASE_NAME}}-${{matrix.architecture}} \ |
| 102 | + -v "$GITHUB_WORKSPACE/${{env.APP_NAME}}:/workspace/${{env.APP_NAME}}" \ |
| 103 | + -w /workspace/${{env.APP_NAME}} \ |
| 104 | + ${{matrix.docker_image}} tail -f /dev/null |
| 105 | +
|
| 106 | + - name: Create debian package |
| 107 | + run: | |
| 108 | + docker exec ${{env.CONTAINER_BASE_NAME}}-${{matrix.architecture}} sh -c ".github/scripts/create_debian.sh ${{needs.identify_version.outputs.app-version}} ${{matrix.architecture}}" |
| 109 | +
|
| 110 | + - name: Install application |
| 111 | + env: |
| 112 | + DEB_FILE_NAME: ${{env.APP_NAME}}_${{needs.identify_version.outputs.app-version}}-1_${{matrix.architecture}} |
| 113 | + run: | |
| 114 | + docker exec ${{env.CONTAINER_BASE_NAME}}-${{matrix.architecture}} sh -c "sudo dpkg -i ../${{env.DEB_FILE_NAME}}.deb" |
| 115 | +
|
| 116 | + - name: Verify install locations |
| 117 | + run: | |
| 118 | + docker exec ${{env.CONTAINER_BASE_NAME}}-${{matrix.architecture}} sh -c ".github/scripts/verify_install.sh" |
| 119 | +
|
| 120 | + - name: Copy .deb from container to host |
| 121 | + env: |
| 122 | + DEB_FILE_NAME: ${{env.APP_NAME}}_${{needs.identify_version.outputs.app-version}}-1_${{matrix.architecture}} |
| 123 | + run: | |
| 124 | + docker cp ${{env.CONTAINER_BASE_NAME}}-${{matrix.architecture}}:/workspace/${{env.DEB_FILE_NAME}}.deb ./${{env.DEB_FILE_NAME}}.deb |
| 125 | +
|
| 126 | + - name: Upload .deb artifacts to github |
| 127 | + uses: actions/upload-artifact@v4 |
| 128 | + with: |
| 129 | + name: ${{env.APP_NAME}}-${{matrix.architecture}} |
| 130 | + path: ${{env.APP_NAME}}_${{needs.identify_version.outputs.app-version}}-1_${{matrix.architecture}}.deb |
| 131 | + if-no-files-found: error |
| 132 | + build_and_deploy_for_ubuntu: |
| 133 | + runs-on: ubuntu-latest |
| 134 | + needs: identify_version |
| 135 | + env: |
| 136 | + architecture: amd64 |
| 137 | + defaults: |
| 138 | + run: |
| 139 | + working-directory: ${{env.APP_NAME}} |
| 140 | + steps: |
| 141 | + - name: Checkout code repository |
| 142 | + uses: actions/checkout@v4 |
| 143 | + with: |
| 144 | + path: ${{env.APP_NAME}} |
| 145 | + |
| 146 | + - name: Create .deb package |
| 147 | + run: | |
| 148 | + .github/scripts/create_debian.sh ${{needs.identify_version.outputs.app-version}} ${{env.architecture}} |
| 149 | +
|
| 150 | + - name: Install application |
| 151 | + env: |
| 152 | + DEB_FILE_NAME: ${{env.APP_NAME}}_${{needs.identify_version.outputs.app-version}}-1_${{env.architecture}} |
| 153 | + run: | |
| 154 | + sudo dpkg -i ../${{env.DEB_FILE_NAME}}.deb |
| 155 | +
|
| 156 | + - name: Verify install locations |
| 157 | + run: | |
| 158 | + .github/scripts/verify_install.sh |
| 159 | +
|
| 160 | + - name: Upload .deb artifacts to github |
| 161 | + uses: actions/upload-artifact@v4 |
| 162 | + with: |
| 163 | + name: ${{env.APP_NAME}}-ubuntu |
| 164 | + path: ${{env.APP_NAME}}_${{needs.identify_version.outputs.app-version}}-1_${{env.architecture}}.deb |
| 165 | + if-no-files-found: error |
| 166 | + create_release_from_tag: |
| 167 | + needs: |
| 168 | + - build_and_deploy_for_kuiper |
| 169 | + - build_and_deploy_for_ubuntu |
| 170 | + - identify_version |
| 171 | + runs-on: ubuntu-latest |
| 172 | + if: ${{needs.identify_version.outputs.can-create-release == 'true'}} |
| 173 | + steps: |
| 174 | + - name: Download all artifacts |
| 175 | + uses: actions/download-artifact@v4 |
| 176 | + with: |
| 177 | + merge-multiple: true |
| 178 | + - name: Release |
| 179 | + uses: ncipollo/release-action@v1 |
| 180 | + with: |
| 181 | + token: ${{secrets.TOKEN_GITHUB}} |
| 182 | + name: Release ${{github.ref_name}} |
| 183 | + artifacts: ${{env.APP_NAME}}_*.deb |
| 184 | + |
0 commit comments