|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +env: |
| 9 | + PROJECT_NAME: "modern-cpp-template" |
| 10 | + BUILD_TYPE: Release |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: ${{ matrix.config.name }} |
| 15 | + runs-on: ${{ matrix.config.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + config: |
| 20 | + - { |
| 21 | + name: "Windows Latest MSVC", |
| 22 | + artifact_ext: '.zip', |
| 23 | + os: windows-latest, |
| 24 | + cc: "cl", |
| 25 | + cxx: "cl", |
| 26 | + environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat", |
| 27 | + } |
| 28 | + - { |
| 29 | + name: "Ubuntu Latest GCC", |
| 30 | + artifact_ext: '.tar.gz', |
| 31 | + os: ubuntu-latest, |
| 32 | + cc: "gcc", |
| 33 | + cxx: "g++", |
| 34 | + } |
| 35 | + - { |
| 36 | + name: "macOS Latest Clang", |
| 37 | + artifact_ext: '.tar.gz', |
| 38 | + os: macos-latest, |
| 39 | + cc: "clang", |
| 40 | + cxx: "clang++", |
| 41 | + } |
| 42 | + |
| 43 | + steps: |
| 44 | + - name: set version name (Windows) |
| 45 | + id: version_win |
| 46 | + if: ${{ runner.os == 'Windows' }} |
| 47 | + run: | |
| 48 | + $TAG = (${env:GITHUB_REF} -replace 'refs/tags/', '') |
| 49 | + echo "::set-output name=name::$TAG" |
| 50 | + |
| 51 | + - name: set version name |
| 52 | + id: version |
| 53 | + if: ${{ runner.os != 'Windows' }} |
| 54 | + run: echo ::set-output name=name::${GITHUB_REF#refs/tags/} |
| 55 | + |
| 56 | + - name: Checkout |
| 57 | + uses: actions/checkout@v2 |
| 58 | + with: |
| 59 | + submodules: recursive |
| 60 | + |
| 61 | + - name: cache dependencies |
| 62 | + uses: actions/cache@v2 |
| 63 | + id: cache |
| 64 | + with: |
| 65 | + path: ${{ github.HOME }}/.local |
| 66 | + key: ${{ runner.os }}-dependencies |
| 67 | + |
| 68 | + - name: install GoogleTest |
| 69 | + if: ${{ steps.cache.output.cache-hit != 'true' }} |
| 70 | + run: | |
| 71 | + cd .. |
| 72 | + git clone https://github.com/google/googletest.git --branch release-1.10.0 |
| 73 | + cd googletest |
| 74 | + cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/.local" -Dgtest_force_shared_crt=1 |
| 75 | + cmake --build build --config Release |
| 76 | + cmake --build build --target install --config Release |
| 77 | + cd ../modern-cpp-template |
| 78 | +
|
| 79 | + - name: configure |
| 80 | + run: cmake -Bbuild -DCMAKE_INSTALL_PREFIX="$HOME/.local" |
| 81 | + |
| 82 | + - name: build |
| 83 | + run: cmake --build build --config "$env:BUILD_TYPE" -j4 |
| 84 | + |
| 85 | + - name: run tests |
| 86 | + run: | |
| 87 | + cd build |
| 88 | + ctest -C "$env:BUILD_TYPE" -VV |
| 89 | +
|
| 90 | + # for a release not containing directly the source code, replace the files archived |
| 91 | + # with the actual files needed (i.e. *.lib/*.a and *.h(pp)) |
| 92 | + |
| 93 | + - name: generate archive (Windows) |
| 94 | + if: ${{ runner.os == 'Windows' }} |
| 95 | + run: | |
| 96 | + rmdir -r -fo build |
| 97 | + 7z a -tzip $HOME/artifact.zip * |
| 98 | +
|
| 99 | +
|
| 100 | + - name: generate archive |
| 101 | + if: ${{ runner.os != 'Windows' }} |
| 102 | + run: | |
| 103 | + rm -rf build |
| 104 | + tar -cvzf $HOME/artifact.tar.gz . |
| 105 | +
|
| 106 | + - name: upload artifacts |
| 107 | + uses: actions/upload-artifact@v2 |
| 108 | + if: ${{ runner.os == 'Windows' }} |
| 109 | + with: |
| 110 | + name: ${{ runner.os }}-${{ steps.version_win.outputs.name }} |
| 111 | + path: '~/artifact.*' |
| 112 | + |
| 113 | + - name: upload artifacts |
| 114 | + uses: actions/upload-artifact@v2 |
| 115 | + if: ${{ runner.os != 'Windows' }} |
| 116 | + with: |
| 117 | + name: ${{ runner.os }}-${{ steps.version.outputs.name }} |
| 118 | + path: '~/artifact.*' |
| 119 | + |
| 120 | + release: |
| 121 | + if: contains(github.ref, 'tags/v') |
| 122 | + runs-on: ubuntu-latest |
| 123 | + needs: build |
| 124 | + |
| 125 | + steps: |
| 126 | + - name: set version name |
| 127 | + id: version |
| 128 | + run: echo ::set-output name=name::${GITHUB_REF#refs/tags/} |
| 129 | + |
| 130 | + - name: create release |
| 131 | + id: create_release |
| 132 | + uses: actions/create-release@v1 |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 135 | + with: |
| 136 | + tag_name: ${{ github.ref }} |
| 137 | + release_name: Release ${{ steps.version.outputs.name }} |
| 138 | + # if needed, you can set the release body here |
| 139 | + #body: "Release notes" |
| 140 | + draft: false |
| 141 | + prerelease: false |
| 142 | + |
| 143 | + - name: download artifact |
| 144 | + uses: actions/download-artifact@v2 |
| 145 | + with: |
| 146 | + name: "Linux-${{ steps.version.outputs.name }}" |
| 147 | + path: ./ |
| 148 | + |
| 149 | + - name: upload ubuntu release asset |
| 150 | + uses: actions/upload-release-asset@v1 |
| 151 | + env: |
| 152 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 153 | + with: |
| 154 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 155 | + asset_path: "artifact.tar.gz" |
| 156 | + asset_name: "${{ env.PROJECT_NAME }}-Linux-${{ steps.version.outputs.name }}.tar.gz" |
| 157 | + asset_content_type: application/x-tar |
| 158 | + |
| 159 | + - name: download artifact |
| 160 | + uses: actions/download-artifact@v2 |
| 161 | + with: |
| 162 | + name: "Windows-${{ steps.version.outputs.name }}" |
| 163 | + path: ./ |
| 164 | + |
| 165 | + - name: upload windows release asset |
| 166 | + uses: actions/upload-release-asset@v1 |
| 167 | + env: |
| 168 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 169 | + with: |
| 170 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 171 | + asset_path: "artifact.zip" |
| 172 | + asset_name: "${{ env.PROJECT_NAME }}-Windows-${{ steps.version.outputs.name }}.zip" |
| 173 | + asset_content_type: application/zip |
| 174 | + |
| 175 | + - name: download artifact |
| 176 | + uses: actions/download-artifact@v2 |
| 177 | + with: |
| 178 | + name: "macOS-${{ steps.version.outputs.name }}" |
| 179 | + path: ./ |
| 180 | + |
| 181 | + - name: upload macos release asset |
| 182 | + uses: actions/upload-release-asset@v1 |
| 183 | + env: |
| 184 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 185 | + with: |
| 186 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 187 | + asset_path: "./artifact.tar.gz" |
| 188 | + asset_name: "${{ env.PROJECT_NAME }}-macOS-${{ steps.version.outputs.name }}.tar.gz" |
| 189 | + asset_content_type: application/x-tar |
0 commit comments