Skip to content

Commit

Permalink
add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDP committed Feb 17, 2021
1 parent 7572554 commit 0b946e4
Show file tree
Hide file tree
Showing 6 changed files with 2,015 additions and 1 deletion.
299 changes: 299 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
on:
push:
tags:
- 'v[0-9]+.*' # Release tags matching v*, i.e. v1.0, v20.15.10

name: Release

jobs:
create_release:
name: Create release
if: >
github.repository_owner == 'primetype'
|| startsWith(github.ref, 'refs/heads/ci/test/')
|| startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-ci-test.')
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release_info.outputs.version }}
tag: ${{ steps.release_info.outputs.tag }}
date: ${{ steps.release_info.outputs.date }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: 'true'

- id: release_info
name: Get release information
run: python3 ci/release-info.py "$GITHUB_EVENT_NAME"

- if: ${{ steps.release_info.outputs.release_type == 'nightly' }}
name: Delete existing nightly releases
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set +e
git ls-remote --tags --refs origin 'refs/tags/nightly*' |
cut -f 2 |
while read ref; do
hub release delete ${ref#refs/tags/}
git push --delete origin $ref
done
- id: create_release
name: Create a draft release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
release_tag='${{ steps.release_info.outputs.tag }}'
hub release create ${{ steps.release_info.outputs.release_flags }} --draft \
-m "Release ${{ steps.release_info.outputs.version }} (in progress)" \
-t $GITHUB_SHA $release_tag
upload_url=$(hub release show -f '%uA' $release_tag)
echo "::set-output name=upload_url::$upload_url"
cache_info:
name: Bootstrap cache
if: >
github.repository_owner == 'primetype'
|| startsWith(github.ref, 'refs/heads/ci/test/')
|| startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-ci-test.')
runs-on: ubuntu-latest
outputs:
crates-io-index-head: ${{ steps.ls-crates-io-index.outputs.head }}
cargo-lock-hash: ${{ steps.hash-cargo-lock.outputs.hash }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- id: ls-crates-io-index
name: Get head commit hash of crates.io registry index
run: |
commit=$(
git ls-remote --heads https://github.com/rust-lang/crates.io-index.git master |
cut -f 1
)
echo "$commit"
echo "::set-output name=head::$commit"
- id: hash-cargo-lock
name: Calculate dependency cache key
run: |
hash=$(
ci/strip-own-version-from-cargo-lock.pl Cargo.lock |
sha1sum | cut -d ' ' -f 1
)
echo "$hash"
echo "::set-output name=hash::$hash"
update_deps:
name: Update dependencies
needs: cache_info
# Caches on Windows and Unix do not interop:
# https://github.com/actions/cache/issues/330#issuecomment-637701649
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Cache cargo registry index
uses: actions/cache@v2
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ needs.cache_info.outputs.crates-io-index-head }}
restore-keys: cargo-index-

- id: cargo-deps
name: Cache cargo dependencies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-deps-v1-${{ needs.cache_info.outputs.cargo-lock-hash }}

- name: Check out the repository
uses: actions/checkout@v2
with:
submodules: true

- name: Fetch dependencies and update cargo registry
run: cargo fetch --locked

build_assets:
name: Build assets
needs: [create_release, cache_info, update_deps]
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: false
matrix:
config:
# Linux
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
# Macos
- { os: macos-latest, target: x86_64-apple-darwin }
target_cpu: [generic, broadwell]
toolchain: [stable]
cross: [false]
include:
# Windows
- config: { os: windows-latest, target: x86_64-pc-windows-msvc }
target_cpu: generic
toolchain: stable-x86_64-pc-windows-msvc
cross: false
# Cross targets
- config: { os: ubuntu-latest, target: aarch64-unknown-linux-gnu }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: arm-unknown-linux-gnueabi }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: armv7-unknown-linux-gnueabihf }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
target_cpu: generic
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: x86_64-unknown-linux-musl }
target_cpu: broadwell
toolchain: stable
cross: true
- config: { os: ubuntu-latest, target: aarch64-linux-android }
target_cpu: generic
toolchain: stable
cross: true
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.config.target }}
override: true
default: true

- name: Checkout code
uses: actions/checkout@v2

- name: Restore cargo registry index
uses: actions/cache@v2
with:
path: ~/.cargo/registry/index
key: cargo-index-${{ needs.cache_info.outputs.crates-io-index-head }}

- name: Restore cargo dependencies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry/cache
~/.cargo/git/db
key: cargo-deps-v1-${{ needs.cache_info.outputs.cargo-lock-hash }}

- name: Create .cargo/config.toml
shell: bash
run: |
mkdir .cargo
cat > .cargo/config.toml <<EOF
[target.${{ matrix.config.target }}]
rustflags = ["-C", "target-cpu=${{ matrix.target_cpu }}", "-C", "lto=thin", "-C", "embed-bitcode=yes"]
EOF
- if: ${{ matrix.cross }}
name: Create Cross.toml
shell: bash
run: |
cat > Cross.toml <<EOF
[build.env]
passthrough = ["DATE"]
EOF
- name: Build asmtpd
uses: actions-rs/cargo@v1
env:
DATE: ${{ needs.create_release.outputs.date }}
with:
use-cross: ${{ matrix.cross }}
command: build
args: >
--manifest-path asmtpd/Cargo.toml
--bin asmtpd
--no-default-features
--verbose
--locked
--release
--target ${{ matrix.config.target }}
- name: Build asmtpd-cli
uses: actions-rs/cargo@v1
env:
DATE: ${{ needs.create_release.outputs.date }}
with:
use-cross: ${{ matrix.cross }}
command: build
args: >
--manifest-path asmtpd/Cargo.toml
--bin asmtpd-cli
--verbose
--locked
--release
--target ${{ matrix.config.target }}
- name: Build asmtp-cli
uses: actions-rs/cargo@v1
env:
DATE: ${{ needs.create_release.outputs.date }}
with:
use-cross: ${{ matrix.cross }}
command: build
args: >
--manifest-path asmtp-cli/Cargo.toml
--bin asmtp-cli
--verbose
--locked
--release
--target ${{ matrix.config.target }}
- id: pack-assets
name: Pack binaries
shell: bash
run: python3 ./ci/pack-assets.py ${{ needs.create_release.outputs.version }} ${{ matrix.config.target }} ${{ matrix.target_cpu }}

- name: Upload binaries to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack-assets.outputs.release-archive }}
asset_name: ${{ steps.pack-assets.outputs.release-archive }}
asset_content_type: ${{ steps.pack-assets.outputs.release-content-type }}

- name: Upload checksum to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ steps.pack-assets.outputs.release-archive }}.sha256
asset_name: ${{ steps.pack-assets.outputs.release-archive }}.sha256
asset_content_type: text/plain

publish_release:
name: Publish release
needs: [create_release, build_assets]
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2

- name: Publish release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
hub release edit --draft=false \
-m 'Release ${{ needs.create_release.outputs.version }}' \
${{ needs.create_release.outputs.tag }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
Cargo.lock
Loading

0 comments on commit 0b946e4

Please sign in to comment.