Skip to content

CD

CD #1064

Workflow file for this run

name: CD
on:
schedule:
- cron: '5 5 * * *'
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name for release'
required: true
default: nightly
push:
tags:
- '*'
env:
CARGO_TERM_COLOR: always
jobs:
create_github_release:
name: Create github release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Get release version from tag
if: env.VERSION == '' && github.event_name != 'workflow_dispatch' && github.event_name != 'schedule'
run: |
if [[ -n "${{ github.event.inputs.tag_name }}" ]]; then
echo "Manual run against a tag; overriding actual tag in the environment..."
echo "VERSION=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> "$GITHUB_ENV"
fi
- name: Get release version from inputs
if: env.VERSION == '' && (github.event_name == 'workflow_dispatch' || github.event_name == 'schedule')
env:
default_tag_name: nightly
run: |
echo "VERSION=${{ github.event.inputs.tag_name || env.default_tag_name }}" >> "$GITHUB_ENV"
- name: Validate version environment variable
run: |
echo "Version being built against is version ${{ env.VERSION }}"!
- name: Save version to output
id: get_version
run: |
echo "version=${{ env.VERSION }}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v3
with:
submodules: true
if: env.VERSION == 'nightly'
# We need to update the nightly tag every night, otherwise the CD
# pipeline will release the same revision every time
- name: Nightly set up
if: env.VERSION == 'nightly'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release delete nightly --yes --cleanup-tag || true
git tag nightly
git push origin nightly
echo "PRELEASE=true" >> $GITHUB_ENV
- if: env.VERSION != 'nightly'
run: |
echo "PRELEASE=false" >> $GITHUB_ENV
- name: Create GitHub release (tag)
if: github.event_name != 'workflow_dispatch' && github.event_name != 'schedule'
id: release_tag
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
draft: true
name: ${{ env.VERSION }}
prerelease: ${{ env.PRELEASE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release (schedule/workflow dispatch)
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
id: release_dispatch
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
allowUpdates: true
name: ${{ env.VERSION }}
tag: ${{ env.VERSION }}
prerelease: ${{ env.PRELEASE }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create artifacts directory
run: mkdir artifacts
- name: Save release upload URL to artifact (tag)
if: github.event_name != 'workflow_dispatch' && github.event_name != 'schedule'
run: echo "${{ steps.release_tag.outputs.upload_url }}" > artifacts/release-upload-url
- name: Save release upload URL to artifact (workflow/schedule)
if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule'
run: echo "${{ steps.release_dispatch.outputs.upload_url }}" > artifacts/release-upload-url
- name: Save version number to artifact
run: echo "${{ env.VERSION }}" > artifacts/release-version
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: artifacts
publish:
name: Publish for ${{ matrix.job.target }}
runs-on: ${{ matrix.job.os }}
needs: [create_github_release]
strategy:
matrix:
job:
- os: ubuntu-latest
artifact_name: diffsitter
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
artifact_name: diffsitter
target: i686-unknown-linux-gnu
- os: ubuntu-latest
artifact_name: diffsitter
target: arm-unknown-linux-gnueabi
- os: ubuntu-latest
artifact_name: diffsitter
target: aarch64-unknown-linux-gnu
- os: macOS-latest
artifact_name: diffsitter
target: x86_64-apple-darwin
- os: macOS-latest
artifact_name: diffsitter
target: aarch64-apple-darwin
- os: windows-latest
artifact_name: diffsitter.exe
target: x86_64-pc-windows-msvc
- os: windows-latest
artifact_name: diffsitter
target: aarch64-pc-windows-msvc
- os: ubuntu-latest
artifact_name: diffsitter
target: x86_64-unknown-freebsd
- os: ubuntu-latest
artifact_name: diffsitter
target: powerpc64le-unknown-linux-gnu
- os: ubuntu-latest
artifact_name: diffsitter
target: riscv64gc-unknown-linux-gnu
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: Swatinem/rust-cache@v2
with:
key: cd-${{steps.toolchain.outputs.name}}
- if: ${{ matrix.job.os == 'ubuntu-latest' }}
name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.job.target }}
- if: ${{ matrix.job.os != 'ubuntu-latest' }}
name: Install native Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
targets: ${{ matrix.job.target }}
components: rustfmt,clippy
toolchain: stable
- uses: taiki-e/install-action@nextest
- name: Install packages (Windows)
if: matrix.job.os == 'windows-latest'
uses: crazy-max/ghaction-chocolatey@v1.4.0
with:
args: install -y zip
- name: Install packages (macOS)
if: matrix.job.os == 'macos-latest'
shell: bash
run: |
brew install coreutils
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Get release download URL
uses: actions/download-artifact@v4
with:
name: artifacts
path: artifacts
- name: Set release upload URL and release version
shell: bash
run: |
release_upload_url="$(cat ./artifacts/release-upload-url)"
echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV
release_version="$(cat ./artifacts/release-version)"
echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV
# For nightly releases we need to manually specify the tag because the
# action was triggered by a schedule not a tag.
# TODO: separate out the logic so we have another action that creates and
# pushes the tag so this file doesn't have to handle that logic. What we
# really should do is simply have this job get triggered by tags and
# have some way to specify whether it's a prerelease tag and handle it
# from there.
- name: Upload Rust binaries for nightly
uses: taiki-e/upload-rust-binary-action@v1
if: needs.create_github_release.outputs.version == 'nightly'
with:
bin: diffsitter
archive: $bin-$target
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}
tar: unix
zip: windows
checksum: sha256
target: ${{ matrix.job.target }}
ref: refs/tags/nightly
include: bin/git-diffsitter
profile: production
- name: Upload Rust binaries for release
uses: taiki-e/upload-rust-binary-action@v1
if: needs.create_github_release.outputs.version != 'nightly'
with:
bin: diffsitter
archive: $bin-$target
# (required) GitHub token for uploading assets to GitHub Releases.
token: ${{ secrets.GITHUB_TOKEN }}
tar: unix
zip: windows
checksum: sha256
target: ${{ matrix.job.target }}
include: bin/git-diffsitter
profile: production
- name: Install cargo deb
uses: taiki-e/install-action@v2
if: matrix.job.target == 'x86_64-unknown-linux-gnu'
with:
tool: cargo-deb@1.43.0
- name: Build Debian release (x86_64-unknown-linux-gnu)
if: matrix.job.target == 'x86_64-unknown-linux-gnu'
run: |
cargo build --profile production --locked
cargo deb --profile production --target ${{ matrix.job.target }} --no-build
cp ./target/${{ matrix.job.target }}/debian/diffsitter_*.deb ./diffsitter_${{ env.RELEASE_VERSION }}_amd64.deb
env:
CARGO_TARGET_DIR: "./target"
- name: Upload Debian file (x86_64-unknown-linux-gnu)
if: matrix.job.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: diffsitter_${{ env.RELEASE_VERSION }}_amd64.deb
asset_name: diffsitter_${{ env.RELEASE_VERSION }}_amd64.deb
asset_content_type: application/octet-stream
- name: Generate tarball with submodules
if: matrix.job.target == 'x86_64-unknown-linux-gnu'
shell: bash
run: |
bash deployment/git-archive-all.bash --prefix "diffsitter_src/" --format tar.gz diffsitter_src.tar.gz
- name: Upload tarball with submodules
if: matrix.job.target == 'x86_64-unknown-linux-gnu'
uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ env.RELEASE_UPLOAD_URL }}
asset_path: diffsitter_src.tar.gz
asset_name: diffsitter_src.tar.gz
asset_content_type: application/octet-stream