Run CI on Ubuntu 20.04 (#16) #104
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: Build and package | |
on: | |
push: | |
branches: [main] | |
tags: ["v*"] | |
pull_request: | |
branches: [main] | |
# TODO: better way? | |
permissions: | |
contents: write | |
jobs: | |
build: | |
name: Build pluginify | |
runs-on: ${{ matrix.config.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
config: | |
- { target: "x86_64-unknown-linux-gnu", os: "ubuntu-20.04", arch: "amd64", extension: "" } | |
- { target: "aarch64-unknown-linux-gnu", os: "ubuntu-20.04", arch: "aarch64", extension: "" } | |
- { target: "x86_64-apple-darwin", os: "macos-latest", arch: "amd64", extension: "" } | |
- { target: "aarch64-apple-darwin", os: "macos-latest", arch: "aarch64", extension: "" } | |
- { target: "x86_64-pc-windows-msvc", os: "windows-latest", arch: "amd64", extension: ".exe" } | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
toolchain: 1.66 | |
targets: ${{ matrix.config.target }} | |
- name: Set up for cross-compiled linux aarch64 build | |
if: matrix.config.target == 'aarch64-unknown-linux-gnu' | |
run: | | |
sudo apt update | |
sudo apt install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu | |
echo '[target.aarch64-unknown-linux-gnu]' >> ${HOME}/.cargo/config.toml | |
echo 'linker = "aarch64-linux-gnu-gcc"' >> ${HOME}/.cargo/config.toml | |
- name: Build plugin binary | |
run: cargo build --release --target ${{ matrix.config.target }} | |
- name: Copy plugin binary to standard location | |
shell: bash | |
run: cp target/${{ matrix.config.target }}/release/pluginify${{ matrix.config.extension }} target/release/pluginify${{ matrix.config.extension }} | |
# We cannot self-pluginify on aarch64 because binaries won't run on the runner | |
# (the runner is always x86). For other plugins, that wouldn't be an issue. | |
# So we'd like to set the merge pattern to fit that scenario. So... we'll cheat. | |
- name: Pluginify - self-pluginify | |
if: ${{ matrix.config.arch == 'amd64' }} | |
run: ./target/release/pluginify | |
- name: Pluginify - build native executable | |
if: ${{ matrix.config.arch != 'amd64' }} | |
run: cargo build | |
- name: Pluginify - use native executable to pluginify aarch64 executable | |
if: ${{ matrix.config.arch != 'amd64' }} | |
run: ./target/debug/pluginify --arch ${{ matrix.config.arch }} | |
# Special treatment for this because we need it for the merge | |
- name: Archive Linux executable | |
if: ${{ matrix.config.target == 'x86_64-unknown-linux-gnu' }} | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pluginify | |
path: target/release/pluginify | |
- name: Archive pluginified | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pluginify-${{ matrix.config.os }}-${{ matrix.config.arch }} | |
path: | | |
*.tar.gz | |
*.json | |
package: | |
name: Package plugin | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: set the release version (tag) | |
if: startsWith(github.ref, 'refs/tags/v') | |
shell: bash | |
run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV | |
- name: set the release version (main) | |
if: github.ref == 'refs/heads/main' | |
shell: bash | |
run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV | |
- name: set the release version (TEST TEST TEST) | |
if: github.event_name == 'pull_request' | |
shell: bash | |
run: echo "RELEASE_VERSION=precanary" >> $GITHUB_ENV | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
- name: Display structure of downloaded files | |
run: ls -R | |
- name: pluginify it | |
run: | | |
chmod +x ./pluginify/pluginify | |
./pluginify/pluginify --merge --release-url-base https://github.com/itowlson/spin-pluginify/releases/download/${{ env.RELEASE_VERSION }}/ >pluginify.json | |
- name: Display merged manifest | |
run: cat pluginify.json | |
# Handle versioned release | |
- name: Upload tars to Github release | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: "**/*.tar.gz" | |
file_glob: true | |
tag: ${{ github.ref }} | |
- name: Upload manifest to Github release | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: pluginify.json | |
tag: ${{ github.ref }} | |
# Handle canary release | |
- name: Delete canary tag | |
if: github.ref == 'refs/heads/main' | |
uses: dev-drprasad/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: canary | |
- name: Recreate canary tag and release | |
if: github.ref == 'refs/heads/main' | |
uses: ncipollo/[email protected] | |
with: | |
tag: canary | |
allowUpdates: true | |
prerelease: true | |
- name: Upload tars to Github release | |
if: github.ref == 'refs/heads/main' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: "**/*.tar.gz" | |
file_glob: true | |
tag: canary | |
- name: Upload manifest to Github release | |
if: github.ref == 'refs/heads/main' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: pluginify.json | |
tag: canary |