|
| 1 | +name: Build and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 |
| 7 | + |
| 8 | +jobs: |
| 9 | + test: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v2 |
| 14 | + |
| 15 | + - name: Read .nvmrc |
| 16 | + run: echo ::set-output name=NVMRC::$(cat .nvmrc) |
| 17 | + id: nvm |
| 18 | + |
| 19 | + - name: Setup Node |
| 20 | + uses: actions/setup-node@v1 |
| 21 | + with: |
| 22 | + node-version: '${{ steps.nvm.outputs.NVMRC }}' |
| 23 | + |
| 24 | + - name: Install |
| 25 | + run: | |
| 26 | + yarn install |
| 27 | +
|
| 28 | + - name: Build |
| 29 | + run: yarn release |
| 30 | + |
| 31 | + - name: Artifact |
| 32 | + uses: actions/upload-artifact@v2 |
| 33 | + with: |
| 34 | + name: ubuntu-latest |
| 35 | + path: dist |
| 36 | + |
| 37 | + |
| 38 | + build: |
| 39 | + needs: test |
| 40 | + strategy: |
| 41 | + fail-fast: true |
| 42 | + matrix: |
| 43 | + os: [macos-latest, windows-latest, ubuntu-latest] |
| 44 | + max-parallel: 3 |
| 45 | + runs-on: ${{ matrix.os }} |
| 46 | + steps: |
| 47 | + - name: Checkout |
| 48 | + uses: actions/checkout@v2 |
| 49 | + |
| 50 | + - name: Read .nvmrc |
| 51 | + run: echo ::set-output name=NVMRC::$(cat .nvmrc) |
| 52 | + id: nvm |
| 53 | + |
| 54 | + - name: Setup Node |
| 55 | + uses: actions/setup-node@v1 |
| 56 | + with: |
| 57 | + node-version: '${{ steps.nvm.outputs.NVMRC }}' |
| 58 | + |
| 59 | + - name: Install |
| 60 | + run: | |
| 61 | + yarn install |
| 62 | +
|
| 63 | + - name: Build |
| 64 | + if: startsWith(matrix.os, 'macos') |
| 65 | + run: | |
| 66 | + yarn release |
| 67 | +
|
| 68 | + - name: Get Change |
| 69 | + if: startsWith(matrix.os, 'ubuntu') |
| 70 | + id: changes |
| 71 | + run: | |
| 72 | + echo "# ${{ github.ref }}" > changes.txt |
| 73 | + sed -n \ |
| 74 | + "$(sed -n '/^## /=' CHANGELOG.md | sed -n '1'p),$(sed -n '/^## /=' CHANGELOG.md | sed -n '2'p)"p \ |
| 75 | + CHANGELOG.md > tmp_changes.txt |
| 76 | +
|
| 77 | + VERSION=$(head -1 tmp_changes.txt | cut -d '[' -f 2 | cut -d ']' -f 1) |
| 78 | + if [ "refs/tags/v$VERSION" != "${{ github.ref }}" ]; then |
| 79 | + echo $VERSION |
| 80 | + echo "${{ github.ref }}" |
| 81 | + echo "changelog version mismatch"; |
| 82 | + exit 1; |
| 83 | + fi |
| 84 | +
|
| 85 | + cat tmp_changes.txt | head -n -1 >> changes.txt |
| 86 | + echo ::set-output name=log::$(cat changes.txt) |
| 87 | +
|
| 88 | + - name: Upload change |
| 89 | + if: startsWith(matrix.os, 'ubuntu') |
| 90 | + uses: actions/upload-artifact@v2 |
| 91 | + with: |
| 92 | + name: changes |
| 93 | + path: changes.txt |
| 94 | + |
| 95 | + - name: Artifact |
| 96 | + uses: actions/upload-artifact@v2 |
| 97 | + with: |
| 98 | + name: ${{ matrix.os }} |
| 99 | + path: dist |
| 100 | + |
| 101 | + release: |
| 102 | + needs: build |
| 103 | + runs-on: ubuntu-latest |
| 104 | + steps: |
| 105 | + - name: Get Changes |
| 106 | + uses: actions/download-artifact@v2 |
| 107 | + with: |
| 108 | + name: changes |
| 109 | + |
| 110 | + - name: Get deployment refs |
| 111 | + id: get_source |
| 112 | + run: | |
| 113 | + echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} |
| 114 | + echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} |
| 115 | + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} |
| 116 | +
|
| 117 | + - name: Create Release |
| 118 | + id: create_release |
| 119 | + uses: actions/create-release@v1 |
| 120 | + env: |
| 121 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token |
| 122 | + with: |
| 123 | + tag_name: ${{ github.ref }} |
| 124 | + release_name: Release ${{ github.ref }} |
| 125 | + # body: ${{ steps.changes.outputs.log }} |
| 126 | + body_path: changes.txt |
| 127 | + # body: ${{ needs.build.outputs.log }} |
| 128 | + # echo ::set-env name=FOO::$(echo -n "hello world") |
| 129 | + draft: false |
| 130 | + prerelease: false |
| 131 | + |
| 132 | + outputs: |
| 133 | + upload_url: ${{ steps.create_release.outputs.upload_url }} |
| 134 | + source_tag: ${{ steps.get_source.outputs.SOURCE_TAG }} |
| 135 | + |
| 136 | + |
| 137 | + upload: |
| 138 | + needs: release |
| 139 | + runs-on: ubuntu-latest |
| 140 | + strategy: |
| 141 | + fail-fast: true |
| 142 | + matrix: |
| 143 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 144 | + max-parallel: 3 |
| 145 | + steps: |
| 146 | + - uses: actions/download-artifact@v2 |
| 147 | + with: |
| 148 | + name: ${{ matrix.os }} |
| 149 | + path: ProjectExportAPI |
| 150 | + |
| 151 | + - name: list path |
| 152 | + if: startsWith(matrix.os, 'windows') |
| 153 | + run: dir ProjectExportAPI |
| 154 | + |
| 155 | + - name: Compress folder |
| 156 | + if: startsWith(matrix.os, 'windows') |
| 157 | + run: cd ProjectExportAPI && 7za a ../ProjectExportAPI.zip |
| 158 | + |
| 159 | + - name: Compress folder |
| 160 | + if: startsWith(matrix.os, 'windows') != true |
| 161 | + run: zip -r ProjectExportAPI.zip ProjectExportAPI/* |
| 162 | + |
| 163 | + - name: Upload Linux Asset |
| 164 | + if: startsWith(matrix.os, 'ubuntu') |
| 165 | + uses: actions/upload-release-asset@v1 |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + with: |
| 169 | + upload_url: ${{ needs.release.outputs.upload_url }} |
| 170 | + asset_path: ProjectExportAPI.zip |
| 171 | + asset_name: ProjectExportAPI-linux.zip |
| 172 | + asset_content_type: application/zip |
| 173 | + |
| 174 | + - name: Upload Mac Asset |
| 175 | + if: startsWith(matrix.os, 'macos') |
| 176 | + uses: actions/upload-release-asset@v1 |
| 177 | + env: |
| 178 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 179 | + with: |
| 180 | + upload_url: ${{ needs.release.outputs.upload_url }} |
| 181 | + asset_path: ProjectExportAPI.zip |
| 182 | + asset_name: ProjectExportAPI-mac.zip |
| 183 | + asset_content_type: application/zip |
| 184 | + |
| 185 | + - name: Upload Windows Asset |
| 186 | + if: startsWith(matrix.os, 'windows') |
| 187 | + uses: actions/upload-release-asset@v1 |
| 188 | + env: |
| 189 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 190 | + with: |
| 191 | + upload_url: ${{ needs.release.outputs.upload_url }} |
| 192 | + asset_path: ProjectExportAPI.zip |
| 193 | + asset_name: ProjectExportAPI-windows.zip |
| 194 | + asset_content_type: application/zip |
0 commit comments