|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ develop, master ] |
| 6 | + pull_request: |
| 7 | + branches: [ develop ] |
| 8 | + release: |
| 9 | + types: [ published ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-20.04 |
| 14 | + |
| 15 | + services: |
| 16 | + postgres: |
| 17 | + image: postgres:13.2 |
| 18 | + env: |
| 19 | + POSTGRES_DB: postgres |
| 20 | + POSTGRES_PASSWORD: postgres |
| 21 | + POSTGRES_USER: postgres |
| 22 | + ports: |
| 23 | + - 5432:5432 |
| 24 | + # Set health checks to wait until postgres has started |
| 25 | + options: >- |
| 26 | + --health-cmd pg_isready |
| 27 | + --health-interval 10s |
| 28 | + --health-timeout 5s |
| 29 | + --health-retries 5 |
| 30 | +
|
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v2 |
| 33 | + |
| 34 | + - name: Install Go |
| 35 | + uses: actions/setup-go@v2 |
| 36 | + with: |
| 37 | + go-version: 1.16.x |
| 38 | + |
| 39 | + - name: Install Node |
| 40 | + uses: actions/setup-node@v2 |
| 41 | + with: |
| 42 | + node-version: '14' |
| 43 | + |
| 44 | + - name: Checkout |
| 45 | + run: git fetch --prune --unshallow --tags |
| 46 | + |
| 47 | + - name: Cache node modules |
| 48 | + uses: actions/cache@v2 |
| 49 | + env: |
| 50 | + cache-name: cache-node_modules |
| 51 | + with: |
| 52 | + path: frontend/node_modules |
| 53 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('frontend/yarn.lock') }} |
| 54 | + |
| 55 | + - name: Cache UI build |
| 56 | + uses: actions/cache@v2 |
| 57 | + id: cache-ui |
| 58 | + env: |
| 59 | + cache-name: cache-ui |
| 60 | + with: |
| 61 | + path: ui/v2.5/build |
| 62 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('frontend/yarn.lock', 'frontend/public/**', 'frontend/src/**', 'graphql/**/*.graphql') }} |
| 63 | + |
| 64 | + - name: Cache go build |
| 65 | + uses: actions/cache@v2 |
| 66 | + env: |
| 67 | + cache-name: cache-go-cache |
| 68 | + with: |
| 69 | + path: .go-cache |
| 70 | + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }} |
| 71 | + |
| 72 | + - name: Pre-install |
| 73 | + run: make pre-ui |
| 74 | + |
| 75 | + - name: Validate UI |
| 76 | + # skip UI validation for pull requests if UI is unchanged |
| 77 | + if: ${{ github.event_name != 'pull_request' || steps.cache-ui.outputs.cache-hit != 'true' }} |
| 78 | + run: make ui-validate |
| 79 | + |
| 80 | + - name: Generate |
| 81 | + run: make generate |
| 82 | + |
| 83 | + - name: Run tests |
| 84 | + run: POSTGRES_DB=postgres:postgres@localhost/postgres?sslmode=disable make vet it |
| 85 | + |
| 86 | + - name: Build UI |
| 87 | + # skip UI build for pull requests if UI is unchanged (UI was cached) |
| 88 | + # this means that the build version/time may be incorrect if the UI is |
| 89 | + # not changed in a pull request |
| 90 | + if: ${{ github.event_name != 'pull_request' || steps.cache-ui.outputs.cache-hit != 'true' }} |
| 91 | + run: make ui-only |
| 92 | + |
| 93 | + - name: Login to DockerHub |
| 94 | + uses: docker/login-action@v1 |
| 95 | + with: |
| 96 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 97 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Crosscompile binaries |
| 100 | + run: make cross-compile |
| 101 | + |
| 102 | + - name: Generate checksums |
| 103 | + run: | |
| 104 | + git describe --tags --exclude latest_develop | tee CHECKSUMS_SHA1 |
| 105 | + sha1sum dist/*/stash-box-* | sed 's/dist\/.*\///g' | tee -a CHECKSUMS_SHA1 |
| 106 | + echo "STASH_BOX_VERSION=$(git describe --tags --exclude latest_develop)" >> $GITHUB_ENV |
| 107 | + echo "RELEASE_DATE=$(date +'%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_ENV |
| 108 | +
|
| 109 | + - name: Upload Windows binary |
| 110 | + # only upload binaries for pull requests |
| 111 | + if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}} |
| 112 | + uses: actions/upload-artifact@v2 |
| 113 | + with: |
| 114 | + name: stash-box-win.exe |
| 115 | + path: dist/stash-box_windows_amd64/stash-box-windows.exe |
| 116 | + - name: Upload OSX binary |
| 117 | + # only upload binaries for pull requests |
| 118 | + if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}} |
| 119 | + uses: actions/upload-artifact@v2 |
| 120 | + with: |
| 121 | + name: stash-box-darwin |
| 122 | + path: dist/stash-box_darwin_amd64/stash-box-darwin |
| 123 | + - name: Upload Linux binary |
| 124 | + # only upload binaries for pull requests |
| 125 | + if: ${{ github.event_name == 'pull_request' && github.base_ref != 'refs/heads/develop' && github.base_ref != 'refs/heads/master'}} |
| 126 | + uses: actions/upload-artifact@v2 |
| 127 | + with: |
| 128 | + name: stash-box-linux |
| 129 | + path: dist/stash-box_linux_amd64/stash-box-linux |
| 130 | + |
| 131 | + - name: Update latest_develop tag |
| 132 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} |
| 133 | + run : git tag -f latest_develop; git push -f --tags |
| 134 | + - name: Development Release |
| 135 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} |
| 136 | + |
| 137 | + with: |
| 138 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 139 | + prerelease: true |
| 140 | + allow_override: true |
| 141 | + tag: latest_develop |
| 142 | + name: "${{ env.STASH_BOX_VERSION }}: Latest development build" |
| 143 | + body: "**${{ env.RELEASE_DATE }}**\n This is always the latest committed version on the develop branch. Use as your own risk!" |
| 144 | + files: | |
| 145 | + dist/stash-box_windows_amd64/stash-box-windows.exe |
| 146 | + dist/stash-box_linux_amd64/stash-box-linux |
| 147 | + dist/stash-box_darwin_amd64/stash-box-darwin |
| 148 | + CHECKSUMS_SHA1 |
| 149 | + gzip: false |
| 150 | + - name: Master release |
| 151 | + if: ${{ github.event_name == 'release' && github.ref != 'refs/tags/latest_develop' }} |
| 152 | + |
| 153 | + with: |
| 154 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 155 | + allow_override: true |
| 156 | + files: | |
| 157 | + dist/stash-box_windows_amd64/stash-box-windows.exe |
| 158 | + dist/stash-box_linux_amd64/stash-box-linux |
| 159 | + dist/stash-box_darwin_amd64/stash-box-darwin |
| 160 | + CHECKSUMS_SHA1 |
| 161 | + gzip: false |
| 162 | + |
| 163 | + - name: Development Docker |
| 164 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/develop' }} |
| 165 | + run: | |
| 166 | + docker build -t stashapp/stash-box:development -f ./docker/ci/x86_64/Dockerfile ./dist |
| 167 | + docker push stashapp/stash-box:development |
| 168 | +
|
| 169 | + - name: Release Docker |
| 170 | + if: ${{ github.event_name == 'release' && github.ref != 'refs/tags/latest_develop' }} |
| 171 | + run: | |
| 172 | + docker build -t stashapp/stash-box:latest -f ./docker/ci/x86_64/Dockerfile ./dist |
| 173 | + docker push stashapp/stash-box:latest |
0 commit comments