]> git.lizzy.rs Git - rust.git/blob - .github/workflows/release.yaml
Refactor release workflow
[rust.git] / .github / workflows / release.yaml
1 name: release
2 on:
3   schedule:
4     - cron: "0 0 * * *" # midnight UTC
5
6   workflow_dispatch:
7
8   push:
9     branches:
10       - release
11       - trigger-nightly
12
13 env:
14   CARGO_INCREMENTAL: 0
15   CARGO_NET_RETRY: 10
16   RUSTFLAGS: "-D warnings -W unreachable-pub"
17   RUSTUP_MAX_RETRIES: 10
18   FETCH_DEPTH: 0 # pull in the tags for the version string
19
20 jobs:
21   dist:
22     strategy:
23       matrix:
24         include:
25           - os: windows-latest
26             target: x86_64-pc-windows-msvc
27           - os: windows-latest
28             target: aarch64-pc-windows-msvc
29           - os: ubuntu-20.04
30             target: x86_64-unknown-linux-gnu
31           - os: ubuntu-20.04
32             target: aarch64-unknown-linux-gnu
33             cross_linker: aarch64-linux-gnu-gcc
34           - os: macos-11
35             target: x86_64-apple-darwin
36           - os: macos-11
37             target: aarch64-apple-darwin
38
39     name: dist (${{ matrix.target }})
40     runs-on: ${{ matrix.os }}
41
42     env:
43       RA_TARGET: ${{ matrix.target }}
44       CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: ${{ matrix.cross_linker }}
45
46     steps:
47       - name: Checkout repository
48         uses: actions/checkout@v2
49         with:
50           fetch-depth: ${{ env.FETCH_DEPTH }}
51
52       # We need to disable the existing toolchain to avoid updating rust-docs
53       # which takes a long time. The fastest way to do this is to rename the
54       # existing folder, as deleting it takes about as much time as not doing
55       # anything and just updating rust-docs.
56       - name: Rename existing Rust toolchain
57         if: matrix.os == 'windows-latest'
58         run: Rename-Item C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc.old
59
60       - name: Install Rust toolchain
61         uses: actions-rs/toolchain@v1
62         with:
63           toolchain: stable
64           target: ${{ matrix.target }}
65           profile: minimal
66           override: true
67
68       - name: Install Rust library source
69         if: matrix.target == 'x86_64-unknown-linux-gnu'
70         uses: actions-rs/toolchain@v1
71         with:
72           toolchain: stable
73           target: ${{ matrix.target }}
74           profile: minimal
75           override: true
76           components: rust-src
77
78       - name: Install Node.js
79         if: matrix.target == 'x86_64-unknown-linux-gnu'
80         uses: actions/setup-node@v1
81         with:
82           node-version: 14.x
83
84       - name: Update apt repositories
85         if: matrix.target == 'aarch64-unknown-linux-gnu'
86         run: sudo apt-get update
87
88       - name: Install target toolchain
89         if: matrix.target == 'aarch64-unknown-linux-gnu'
90         run: sudo apt-get install gcc-aarch64-linux-gnu
91
92       - name: Dist (generic)
93         if: matrix.target != 'x86_64-unknown-linux-gnu'
94         run: cargo xtask dist
95
96       - name: Dist (Linux)
97         if: matrix.target == 'x86_64-unknown-linux-gnu'
98         run: cargo xtask dist --client-patch-version $GITHUB_RUN_NUMBER
99
100       - name: Run analysis-stats on rust-analyzer
101         if: matrix.target == 'x86_64-unknown-linux-gnu'
102         run: target/${{ matrix.target }}/release/rust-analyzer analysis-stats .
103
104       - name: Run analysis-stats on rust std library
105         if: matrix.target == 'x86_64-unknown-linux-gnu'
106         run: target/${{ matrix.target }}/release/rust-analyzer analysis-stats --with-deps $(rustc --print sysroot)/lib/rustlib/src/rust/library/std
107
108       - name: Upload artifacts
109         uses: actions/upload-artifact@v1
110         with:
111           name: dist-${{ matrix.target }}
112           path: ./dist
113
114   dist-x86_64-unknown-linux-musl:
115     name: dist (x86_64-unknown-linux-musl)
116     runs-on: ubuntu-latest
117     env:
118       RA_TARGET: x86_64-unknown-linux-musl
119       # For some reason `-crt-static` is not working for clang without lld
120       RUSTFLAGS: "-C link-arg=-fuse-ld=lld -C target-feature=-crt-static"
121     container:
122       image: rust:alpine
123       volumes:
124         - /usr/local/cargo/registry
125
126     steps:
127       - name: Install dependencies
128         run: apk add --no-cache git clang lld musl-dev
129
130       - name: Checkout repository
131         uses: actions/checkout@v2
132         with:
133           fetch-depth: ${{ env.FETCH_DEPTH }}
134
135       - name: Dist
136         run: cargo xtask dist
137
138       - name: Upload artifacts
139         uses: actions/upload-artifact@v1
140         with:
141           name: dist-x86_64-unknown-linux-musl
142           path: ./dist
143
144   publish:
145     name: publish
146     runs-on: ubuntu-latest
147     needs: ["dist", "dist-x86_64-unknown-linux-musl"]
148     steps:
149       - name: Install Nodejs
150         uses: actions/setup-node@v1
151         with:
152           node-version: 14.x
153
154       - run: echo "TAG=$(date --iso -u)" >> $GITHUB_ENV
155         if: github.ref == 'refs/heads/release'
156       - run: echo "TAG=nightly" >> $GITHUB_ENV
157         if: github.ref != 'refs/heads/release'
158       - run: 'echo "TAG: $TAG"'
159
160       - name: Checkout repository
161         uses: actions/checkout@v2
162         with:
163           fetch-depth: ${{ env.FETCH_DEPTH }}
164
165       - run: echo "HEAD_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
166       - run: 'echo "HEAD_SHA: $HEAD_SHA"'
167
168       - uses: actions/download-artifact@v1
169         with:
170           name: dist-aarch64-apple-darwin
171           path: dist
172       - uses: actions/download-artifact@v1
173         with:
174           name: dist-x86_64-apple-darwin
175           path: dist
176       - uses: actions/download-artifact@v1
177         with:
178           name: dist-x86_64-unknown-linux-gnu
179           path: dist
180       - uses: actions/download-artifact@v1
181         with:
182           name: dist-x86_64-unknown-linux-musl
183           path: dist
184       - uses: actions/download-artifact@v1
185         with:
186           name: dist-aarch64-unknown-linux-gnu
187           path: dist
188       - uses: actions/download-artifact@v1
189         with:
190           name: dist-x86_64-pc-windows-msvc
191           path: dist
192       - uses: actions/download-artifact@v1
193         with:
194           name: dist-aarch64-pc-windows-msvc
195           path: dist
196       - run: ls -al ./dist
197
198       - name: Publish Release
199         uses: ./.github/actions/github-release
200         with:
201           files: "dist/*"
202           name: ${{ env.TAG }}
203           token: ${{ secrets.GITHUB_TOKEN }}
204
205       - run: npm ci
206         working-directory: ./editors/code
207
208       - name: Publish Extension
209         if: github.ref == 'refs/heads/release'
210         working-directory: ./editors/code
211         # token from https://dev.azure.com/rust-analyzer/
212         run: npx vsce publish --pat ${{ secrets.MARKETPLACE_TOKEN }} --packagePath ../../dist/rust-analyzer.vsix