fork/helix

git clone https://git.julia.blue/fork/helix

Michael DavisUpdate upload/download-artifact actions to v4 (#9120)585402d9

25.01
9.3 KiB295 linesraw
1name: Release
2on:
3  push:
4    tags:
5    - '[0-9]+.[0-9]+'
6    - '[0-9]+.[0-9]+.[0-9]+'
7    branches:
8    - 'patch/ci-release-*'
9  pull_request:
10    paths:
11    - '.github/workflows/release.yml'
12
13env:
14  # Preview mode: Publishes the build output as a CI artifact instead of creating
15  # a release, allowing for manual inspection of the output. This mode is
16  # activated if the CI run was triggered by events other than pushed tags, or
17  # if the repository is a fork.
18  preview: ${{ !startsWith(github.ref, 'refs/tags/') || github.repository != 'helix-editor/helix' }}
19
20jobs:
21  fetch-grammars:
22    name: Fetch Grammars
23    runs-on: ubuntu-latest
24    steps:
25      - name: Checkout sources
26        uses: actions/checkout@v4
27
28      - name: Install stable toolchain
29        uses: dtolnay/rust-toolchain@stable
30
31      - uses: Swatinem/rust-cache@v2
32
33      - name: Fetch tree-sitter grammars
34        run: cargo run --package=helix-loader --bin=hx-loader
35
36      - name: Bundle grammars
37        run: tar cJf grammars.tar.xz -C runtime/grammars/sources .
38
39      - uses: actions/upload-artifact@v4
40        with:
41          name: grammars
42          path: grammars.tar.xz
43
44  dist:
45    name: Dist
46    needs: [fetch-grammars]
47    env:
48      # For some builds, we use cross to test on 32-bit and big-endian
49      # systems.
50      CARGO: cargo
51      # When CARGO is set to CROSS, this is set to `--target matrix.target`.
52      TARGET_FLAGS:
53      # When CARGO is set to CROSS, TARGET_DIR includes matrix.target.
54      TARGET_DIR: ./target
55      # Emit backtraces on panics.
56      RUST_BACKTRACE: 1
57    runs-on: ${{ matrix.os }}
58    strategy:
59      fail-fast: false # don't fail other jobs if one fails
60      matrix:
61        build: [x86_64-linux, x86_64-macos, x86_64-windows] #, x86_64-win-gnu, win32-msvc
62        include:
63        - build: x86_64-linux
64          os: ubuntu-latest
65          rust: stable
66          target: x86_64-unknown-linux-gnu
67          cross: false
68        - build: aarch64-linux
69          os: ubuntu-latest
70          rust: stable
71          target: aarch64-unknown-linux-gnu
72          cross: true
73        # - build: riscv64-linux
74        #   os: ubuntu-latest
75        #   rust: stable
76        #   target: riscv64gc-unknown-linux-gnu
77        #   cross: true
78        - build: x86_64-macos
79          os: macos-latest
80          rust: stable
81          target: x86_64-apple-darwin
82          cross: false
83        - build: x86_64-windows
84          os: windows-latest
85          rust: stable
86          target: x86_64-pc-windows-msvc
87          cross: false
88        # 23.03: build issues
89        - build: aarch64-macos
90          os: macos-latest
91          rust: stable
92          target: aarch64-apple-darwin
93          cross: false
94          skip_tests: true  # x86_64 host can't run aarch64 code
95        # - build: x86_64-win-gnu
96        #   os: windows-2019
97        #   rust: stable-x86_64-gnu
98        #   target: x86_64-pc-windows-gnu
99        # - build: win32-msvc
100        #   os: windows-2019
101        #   rust: stable
102        #   target: i686-pc-windows-msvc
103
104    steps:
105      - name: Checkout sources
106        uses: actions/checkout@v4
107
108      - name: Download grammars
109        uses: actions/download-artifact@v4
110
111      - name: Move grammars under runtime
112        if: "!startsWith(matrix.os, 'windows')"
113        run: |
114          mkdir -p runtime/grammars/sources
115          tar xJf grammars/grammars.tar.xz -C runtime/grammars/sources
116
117      # The rust-toolchain action ignores rust-toolchain.toml files.
118      # Removing this before building with cargo ensures that the rust-toolchain
119      # is considered the same between installation and usage.
120      - name: Remove the rust-toolchain.toml file
121        run: rm rust-toolchain.toml
122
123      - name: Install ${{ matrix.rust }} toolchain
124        uses: dtolnay/rust-toolchain@master
125        with:
126          toolchain: ${{ matrix.rust }}
127          target: ${{ matrix.target }}
128
129      # Install a pre-release version of Cross
130      # TODO: We need to pre-install Cross because we need cross-rs/cross#591 to
131      #       get a newer C++ compiler toolchain. Remove this step when Cross
132      #       0.3.0, which includes cross-rs/cross#591, is released.
133      - name: Install Cross
134        if: "matrix.cross"
135        run: |
136          cargo install cross --git https://github.com/cross-rs/cross.git --rev 47df5c76e7cba682823a0b6aa6d95c17b31ba63a
137          echo "CARGO=cross" >> $GITHUB_ENV
138        # echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV
139        # echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV
140
141      - name: Show command used for Cargo
142        run: |
143          echo "cargo command is: ${{ env.CARGO }}"
144          echo "target flag is: ${{ env.TARGET_FLAGS }}"
145
146      - name: Run cargo test
147        if: "!matrix.skip_tests"
148        run: ${{ env.CARGO }} test --release --locked --target ${{ matrix.target }} --workspace
149
150      - name: Set profile.release.strip = true
151        shell: bash
152        run: |
153          cat >> .cargo/config.toml <<EOF
154          [profile.release]
155          strip = true
156          EOF
157
158      - name: Build release binary
159        run: ${{ env.CARGO }} build --release --locked --target ${{ matrix.target }}
160
161      - name: Build AppImage
162        shell: bash
163        if: matrix.build == 'x86_64-linux'
164        run: |
165          # Required as of 22.x https://github.com/AppImage/AppImageKit/wiki/FUSE
166          sudo add-apt-repository universe
167          sudo apt install libfuse2
168
169          mkdir dist
170
171          name=dev
172          if [[ $GITHUB_REF == refs/tags/* ]]; then
173            name=${GITHUB_REF:10}
174          fi
175
176          build="${{ matrix.build }}"
177
178          export VERSION="$name"
179          export ARCH=${build%-linux}
180          export APP=helix
181          export OUTPUT="helix-$VERSION-$ARCH.AppImage"
182          export UPDATE_INFORMATION="gh-releases-zsync|$GITHUB_REPOSITORY_OWNER|helix|latest|$APP-*-$ARCH.AppImage.zsync"
183
184          mkdir -p "$APP.AppDir"/usr/{bin,lib/helix}
185
186          cp "target/${{ matrix.target }}/release/hx" "$APP.AppDir/usr/bin/hx"
187          rm -rf runtime/grammars/sources
188          cp -r runtime "$APP.AppDir/usr/lib/helix/runtime"
189
190          cat << 'EOF' > "$APP.AppDir/AppRun"
191          #!/bin/sh
192
193          APPDIR="$(dirname "$(readlink -f "${0}")")"
194          HELIX_RUNTIME="$APPDIR/usr/lib/helix/runtime" exec "$APPDIR/usr/bin/hx" "$@"
195          EOF
196          chmod 755 "$APP.AppDir/AppRun"
197
198          curl -Lo linuxdeploy-x86_64.AppImage \
199              https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage
200          chmod +x linuxdeploy-x86_64.AppImage
201
202          ./linuxdeploy-x86_64.AppImage \
203              --appdir "$APP.AppDir" -d contrib/Helix.desktop \
204              -i contrib/helix.png --output appimage
205
206          mv "$APP-$VERSION-$ARCH.AppImage" \
207              "$APP-$VERSION-$ARCH.AppImage.zsync" dist
208
209      - name: Build archive
210        shell: bash
211        run: |
212          mkdir -p dist
213          if [ "${{ matrix.os }}" = "windows-2019" ]; then
214            cp "target/${{ matrix.target }}/release/hx.exe" "dist/"
215          else
216            cp "target/${{ matrix.target }}/release/hx" "dist/"
217          fi
218          if [ -d runtime/grammars/sources ]; then
219            rm -rf runtime/grammars/sources
220          fi
221          cp -r runtime dist
222
223      - uses: actions/upload-artifact@v4
224        with:
225          name: bins-${{ matrix.build }}
226          path: dist
227
228  publish:
229    name: Publish
230    needs: [dist]
231    runs-on: ubuntu-latest
232    steps:
233      - name: Checkout sources
234        uses: actions/checkout@v4
235
236      - uses: actions/download-artifact@v4
237
238      - name: Build archive
239        shell: bash
240        run: |
241          set -ex
242
243          source="$(pwd)"
244          mkdir -p runtime/grammars/sources
245          tar xJf grammars/grammars.tar.xz -C runtime/grammars/sources
246          rm -rf grammars
247
248          cd "$(mktemp -d)"
249          mv $source/bins-* .
250          mkdir dist
251
252          for dir in bins-* ; do
253              platform=${dir#"bins-"}
254              if [[ $platform =~ "windows" ]]; then
255                  exe=".exe"
256              fi
257              pkgname=helix-$GITHUB_REF_NAME-$platform
258              mkdir -p $pkgname
259              cp $source/LICENSE $source/README.md $pkgname
260              mkdir $pkgname/contrib
261              cp -r $source/contrib/completion $pkgname/contrib
262              mv bins-$platform/runtime $pkgname/
263              mv bins-$platform/hx$exe $pkgname
264              chmod +x $pkgname/hx$exe
265
266              if [[ "$platform" = "x86_64-linux" ]]; then
267                  mv bins-$platform/helix-*.AppImage* dist/
268              fi
269
270              if [ "$exe" = "" ]; then
271                  tar cJf dist/$pkgname.tar.xz $pkgname
272              else
273                  7z a -r dist/$pkgname.zip $pkgname
274              fi
275          done
276
277          tar cJf dist/helix-$GITHUB_REF_NAME-source.tar.xz -C $source .
278          mv dist $source/
279
280      - name: Upload binaries to release
281        uses: svenstaro/upload-release-action@v2
282        if: env.preview == 'false'
283        with:
284          repo_token: ${{ secrets.GITHUB_TOKEN }}
285          file: dist/*
286          file_glob: true
287          tag: ${{ github.ref_name }}
288          overwrite: true
289      
290      - name: Upload binaries as artifact
291        uses: actions/upload-artifact@v4
292        if: env.preview == 'true'
293        with:
294          name: release
295          path: dist/*