■ ■ ■ ■ ■ ■
.github/workflows/release.yml
| 1 | + | name: Build Gophish Release |
| 2 | + | on: |
| 3 | + | release: |
| 4 | + | types: [created] |
| 5 | + | |
| 6 | + | jobs: |
| 7 | + | build: |
| 8 | + | name: Build Binary |
| 9 | + | runs-on: ${{ matrix.os }} |
| 10 | + | strategy: |
| 11 | + | matrix: |
| 12 | + | os: [windows-latest, ubuntu-latest, macos-latest] |
| 13 | + | arch: ['386', amd64] |
| 14 | + | # We sometimes use different verbiage for things (e.g. "darwin" |
| 15 | + | # for the GOOS build flag and "osx" in the actual release ZIP). |
| 16 | + | # We need to specify those here. |
| 17 | + | include: |
| 18 | + | - os: windows-latest |
| 19 | + | goos: windows |
| 20 | + | bin: 'gophish.exe' |
| 21 | + | releaseos: windows |
| 22 | + | - os: ubuntu-latest |
| 23 | + | goos: linux |
| 24 | + | bin: 'gophish' |
| 25 | + | releaseos: linux |
| 26 | + | - os: macos-latest |
| 27 | + | goos: darwin |
| 28 | + | bin: 'gophish' |
| 29 | + | releaseos: osx |
| 30 | + | # Don't build windows-32bit due to missing MinGW dependencies |
| 31 | + | # Don't build osx-32bit due to eventual drop in Go support |
| 32 | + | exclude: |
| 33 | + | - os: windows-latest |
| 34 | + | arch: '386' |
| 35 | + | - os: macos-latest |
| 36 | + | arch: '386' |
| 37 | + | steps: |
| 38 | + | - name: Set up Go |
| 39 | + | uses: actions/setup-go@v2 |
| 40 | + | with: |
| 41 | + | go-version: 1.14 |
| 42 | + | - if: matrix.os == 'ubuntu-latest' |
| 43 | + | run: sudo apt-get update && sudo apt-get install -y gcc-multilib |
| 44 | + | - if: matrix.arch == '386' |
| 45 | + | run: echo "::set-env name=RELEASE::gophish-${{ github.event.release.tag_name }}-${{ matrix.releaseos}}-32bit" |
| 46 | + | - if: matrix.arch == 'amd64' |
| 47 | + | run: echo "::set-env name=RELEASE::gophish-${{ github.event.release.tag_name}}-${{ matrix.releaseos}}-64bit" |
| 48 | + | - uses: actions/checkout@v2 |
| 49 | + | - name: Build ${{ matrix.goos }}/${{ matrix.arch }} |
| 50 | + | run: go build -o ${{ matrix.bin }} |
| 51 | + | env: |
| 52 | + | GOOS: ${{ matrix.goos }} |
| 53 | + | GOARCH: ${{ matrix.arch }} |
| 54 | + | CGO_ENABLED: 1 |
| 55 | + | - name: Upload to artifacts |
| 56 | + | uses: actions/upload-artifact@v2 |
| 57 | + | with: |
| 58 | + | name: ${{ env.RELEASE }} |
| 59 | + | path: ${{ matrix.bin }} |
| 60 | + | |
| 61 | + | package: |
| 62 | + | name: Package Assets |
| 63 | + | runs-on: ubuntu-latest |
| 64 | + | needs: build |
| 65 | + | steps: |
| 66 | + | - uses: actions/checkout@v2 |
| 67 | + | - uses: actions/download-artifact@v2 |
| 68 | + | with: |
| 69 | + | path: bin |
| 70 | + | - name: Package Releases |
| 71 | + | run: | |
| 72 | + | mkdir releases; |
| 73 | + | for RELEASE_DIR in bin/* |
| 74 | + | do |
| 75 | + | echo "Creating release $RELEASE_DIR" |
| 76 | + | for BINARY in $RELEASE_DIR/* |
| 77 | + | do |
| 78 | + | cp $BINARY .; |
| 79 | + | zip -r releases/$(basename $RELEASE_DIR).zip \ |
| 80 | + | $(basename ${BINARY}) \ |
| 81 | + | static/js/dist \ |
| 82 | + | static/js/src/vendor/ckeditor \ |
| 83 | + | static/css/dist \ |
| 84 | + | static/images \ |
| 85 | + | static/font \ |
| 86 | + | static/db \ |
| 87 | + | db \ |
| 88 | + | templates \ |
| 89 | + | README.md \ |
| 90 | + | VERSION \ |
| 91 | + | LICENSE \ |
| 92 | + | config.json; |
| 93 | + | rm $BINARY; |
| 94 | + | done |
| 95 | + | done |
| 96 | + | - name: Upload to artifacts |
| 97 | + | uses: actions/upload-artifact@v2 |
| 98 | + | with: |
| 99 | + | name: releases |
| 100 | + | path: releases/*.zip |
| 101 | + | |
| 102 | + | upload: |
| 103 | + | name: Upload to the Release |
| 104 | + | runs-on: ubuntu-latest |
| 105 | + | needs: package |
| 106 | + | steps: |
| 107 | + | - uses: actions/download-artifact@v2 |
| 108 | + | with: |
| 109 | + | name: releases |
| 110 | + | path: releases/ |
| 111 | + | # I would love to use @actions/upload-release-asset, but they don't |
| 112 | + | # support wildcards in the asset path. Ref #9, #24, and #47 |
| 113 | + | - name: Upload Archives to Release |
| 114 | + | env: |
| 115 | + | UPLOAD_URL: ${{ github.event.release.upload_url }} |
| 116 | + | API_HEADER: "Accept: application/vnd.github.v3+json" |
| 117 | + | AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 118 | + | run: | |
| 119 | + | UPLOAD_URL=$(echo -n $UPLOAD_URL | sed s/\{.*//g) |
| 120 | + | for FILE in releases/* |
| 121 | + | do |
| 122 | + | echo "Uploading ${FILE}"; |
| 123 | + | curl \ |
| 124 | + | -H "${API_HEADER}" \ |
| 125 | + | -H "${AUTH_HEADER}" \ |
| 126 | + | -H "Content-Type: $(file -b --mime-type ${FILE})" \ |
| 127 | + | --data-binary "@${FILE}" \ |
| 128 | + | "${UPLOAD_URL}?name=$(basename ${FILE})"; |
| 129 | + | done |
| 130 | + | - name: Generate SHA256 Hashes |
| 131 | + | env: |
| 132 | + | API_HEADER: "Accept: application/vnd.github.v3+json" |
| 133 | + | AUTH_HEADER: "Authorization: token ${{ secrets.GITHUB_TOKEN }}" |
| 134 | + | RELEASE_URL: ${{ github.event.release.url }} |
| 135 | + | run: | |
| 136 | + | HASH_TABLE="| SHA256 Hash | Filename |" |
| 137 | + | HASH_TABLE="${HASH_TABLE}\n|-----|-----|\n" |
| 138 | + | for FILE in releases/* |
| 139 | + | do |
| 140 | + | FILENAME=$(basename ${FILE}) |
| 141 | + | HASH=$(sha256sum ${FILE} | cut -d ' ' -f 1) |
| 142 | + | HASH_TABLE="${HASH_TABLE}|${HASH}|${FILENAME}|\n" |
| 143 | + | done |
| 144 | + | echo "${HASH_TABLE}" |
| 145 | + | curl \ |
| 146 | + | -XPATCH \ |
| 147 | + | -H "${API_HEADER}" \ |
| 148 | + | -H "${AUTH_HEADER}" \ |
| 149 | + | -H "Content-Type: application/json" \ |
| 150 | + | -d "{\"body\": \"${HASH_TABLE}\"}" \ |
| 151 | + | "${RELEASE_URL}"; |
| 152 | + | |