summaryrefslogtreecommitdiffstats
path: root/.github/workflows/workflow.yml
blob: d6d10b4ad4f0db9a0b1c815ca3f4483608b9c6b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
name: Main workflow
on:
  push:
    paths-ignore:
      - "docs/**"
      - "**.md"
  pull_request:
    paths-ignore:
      - "docs/**"
      - "**.md"

jobs:
  # Run the `rustfmt` code formatter
  rustfmt:
    name: Rustfmt [Formatter]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: rustfmt
          override: true
      - run: rustup component add rustfmt
      - uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  # Run the `clippy` linting tool
  clippy:
    name: Clippy [Linter]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          components: clippy
          override: true
      - uses: actions-rs/clippy-check@v1
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          args: --all-targets --all-features -- -D clippy::all

  # Run a security audit on dependencies
  cargo_audit:
    name: Cargo Audit [Security]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - run: cargo install --force cargo-audit
      - run: cargo generate-lockfile
      - uses: actions-rs/cargo@v1
        with:
          command: audit

  # Ensure that the project could be successfully compiled
  cargo_check:
    name: Compile
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all

  # Run tests on Linux, macOS, and Windows
  # On both Rust stable and Rust nightly
  test:
    name: Test Suite
    needs: [cargo_check]
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        rust: [stable, nightly]
    steps:
      # Checkout the branch being tested
      - uses: actions/checkout@v1

      # Install all the required dependencies for testing
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

      # Install Node.js at a fixed version
      - uses: actions/setup-node@v1
        with:
          node-version: "12.0.0"

      # Install Golang at a fixed version
      - uses: actions/setup-go@v1
        with:
          go-version: "1.12.1"

      # Install Ruby at a fixed version
      - uses: actions/setup-ruby@v1
        with:
          ruby-version: "2.6.3"

      # Install Python at a fixed version
      - uses: actions/setup-python@v1
        with:
          python-version: "3.7.5"

      # Install dotnet at a fixed version
      - uses: actions/setup-dotnet@v1
        with:
          dotnet-version: "2.2.402"

      # Install PHP at a fixed version
      - uses: shivammathur/setup-php@v1
        with:
          php-version: "7.3"

      # Install Mercurial (pre-installed on linux, installed from pip on macos
      # and from choco on windows),
      - name: Install Mercurial (macos)
        if: matrix.os == 'macOS-latest'
        env:
          HGPYTHON3: 1
        run: pip install mercurial
      - name: Install Mercurial (windows)
        if: matrix.os == 'windows-latest'
        run: choco install hg

      # Install Terraform at a fixed version
      - uses: volcano-coffee-company/setup-terraform@v1
        with:
          version: "0.12.14"

      # Run the ignored tests that expect the above setup
      - name: Run all tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: -- -Z unstable-options --include-ignored

  # Run the tests in the Docker image
  docker_test:
    name: Test in Docker
    needs: [cargo_check]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@master
      - name: Pull the pre-built Docker image
        run: docker pull starshipcommand/starship-test
      - name: Fix file permissions
        run: chmod -R a+w .
      - name: Build the Docker image
        run:
          docker build -f tests/Dockerfile --tag starshipcommand/starship-test --cache-from
          starshipcommand/starship-test .
      - name: Run tests in Docker
        run: docker run --rm -v $(pwd):/src/starship starshipcommand/starship-test

  # Publish starship to Crates.io
  cargo_publish:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Publish Cargo Package
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - run: cargo login $CRATES_IO_TOKEN
      - run: cargo publish
    env:
      CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

  update_brew_formula:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Update Brew Formula
    runs-on: macos-latest
    steps:
      - uses: actions/checkout@v1
      - run: |
          echo "https://matchai:$HOMEBREW_GITHUB_API_TOKEN@github.com" > ~/.git-credentials
          git config --global credential.helper store
          git config --global user.name "Matan Kushner"
          git config --global user.email "hello@matchai.dev"

          cd $(brew --repo homebrew/core)	
          git fetch origin
          sudo git reset --hard origin/master	
          cd -

          brew bump-formula-pr --url=https://github.com/starship/starship/archive/$(git describe --tags).tar.gz --message="Automated release pull request using continuous integration." --no-browse -v starship --force
        env:
          HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}

  # Build sources for every OS
  github_build:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Build release binaries
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - x86_64-unknown-linux-musl
          - x86_64-apple-darwin
          - x86_64-pc-windows-msvc
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            name: starship-x86_64-unknown-linux-gnu.tar.gz
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            name: starship-x86_64-unknown-linux-musl.tar.gz
          - target: x86_64-apple-darwin
            os: macOS-latest
            name: starship-x86_64-apple-darwin.tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: starship-x86_64-pc-windows-msvc.zip
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v1

      - name: Install Rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          target: ${{ matrix.target }}

      - name: Install musl tools
        if: matrix.target == 'x86_64-unknown-linux-musl'
        # Install libssl-dev for openssl-sys
        run: sudo apt-get install -y musl-tools libssl-dev 

      - name: Build target
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --release --target ${{ matrix.target }}

      - name: Prepare build artifacts [Windows]
        if: matrix.os == 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          strip starship.exe
          7z a ../../../${{ matrix.name }} starship.exe
          cd -

      - name: Prepare build artifacts [-nix]
        if: matrix.os != 'windows-latest'
        run: |
          cd target/${{ matrix.target }}/release
          strip starship
          tar czvf ../../../${{ matrix.name }} starship
          cd -

      - name: Upload build artifact
        uses: actions/upload-artifact@v1
        with:
          name: ${{ matrix.name }}
          path: ${{ matrix.name }}

  # Create GitHub release with Rust build targets and release notes
  github_release:
    if: startsWith(github.ref, 'refs/tags/v')
    name: Create GitHub Release
    needs: github_build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1

      # These can be squashed when https://github.com/actions/download-artifact/issues/6 is closed
      - name: Download releases from github_build
        uses: actions/download-artifact@v1
        with:
          name: starship-x86_64-unknown-linux-gnu.tar.gz
          path: .
      - name: Download releases from github_build
        uses: actions/download-artifact@v1
        with:
          name: starship-x86_64-unknown-linux-musl.tar.gz
          path: .
      - name: Download releases from github_build
        uses: actions/download-artifact@v1
        with:
          name: starship-x86_64-apple-darwin.tar.gz
          path: .
      - name: Download releases from github_build
        uses: actions/download-artifact@v1
        with:
          name: starship-x86_64-pc-windows-msvc.zip
          path: .

      - name: Generate checksums
        run: for file in starship-*; do openssl dgst -sha256 -r "$file" | awk '{print $1}' > "${file}.sha256"; done

      - name: Generate release notes
        run: |
          # Temporary fix for https://github.com/actions/setup-go/issues/14
          export PATH=$PATH:$(go env GOPATH)/bin
          go get -u github.com/git-chglog/git-chglog/cmd/git-chglog