Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload binaries to github release in actions #208

Merged
merged 2 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,43 +169,38 @@ jobs:
- name: Run semver-checks
run: cargo run semver-checks check-release --manifest-path="crate/core-graphics/Cargo.toml"

publish:
name: Publish to crates.io
runs-on: ubuntu-latest
init-release:
name: Run the release workflow
needs:
- should-publish
- ci-everything
- pre-publish-checks
if: needs.should-publish.outputs.is_new_version == 'yes' && github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: true

- name: Tag the version
run: |
set -euxo pipefail
export CURRENT_VERSION="$(./scripts/get_current_version.sh cargo-semver-checks)"
git tag "v$CURRENT_VERSION"
git push origin "v$CURRENT_VERSION"

- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish
uses: ./.github/workflows/release.yml
with:
publish-tag: ${{ needs.should-publish.outputs.publish-tag }}
secrets:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

should-publish:
name: Check if version changed
runs-on: ubuntu-latest
outputs:
is_new_version: ${{ steps.check.outputs.is_new_version }}
publish-tag: ${{ steps.tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2

- id: check
Expand All @@ -222,6 +217,11 @@ jobs:
# Unexpected outcome, indicates a bug.
exit "$EXIT_CODE"
fi
- name: Determine the tag name
id: tag
run: |
export TAG_NAME="v$(./scripts/get_current_version.sh cargo-semver-checks)"
echo "tag=$TAG_NAME" >> $GITHUB_OUTPUT

pre-publish-checks:
name: Check for semver compliance
Expand Down
96 changes: 96 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Release

on:
workflow_call:
inputs:
publish-tag:
required: true
type: string
secrets:
CARGO_REGISTRY_TOKEN:
required: true

env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always

jobs:
create-release:
name: Create release
runs-on: ubuntu-latest
obi1kenobi marked this conversation as resolved.
Show resolved Hide resolved
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: true

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- uses: Swatinem/rust-cache@v2

- name: Publish
run: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put the git tag step here, between the cargo publish and the GitHub release.

- name: Tag the version
run: |
git tag "${{ inputs.publish-tag }}"
git push origin "${{ inputs.publish-tag }}"
- uses: taiki-e/create-gh-release-action@v1
name: Create github release
with:
branch: main
ref: refs/tags/${{ inputs.publish-tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

upload-binary:
name: ${{ matrix.target }}
needs:
- create-release
strategy:
matrix:
include:
- target: aarch64-unknown-linux-gnu
- target: aarch64-unknown-linux-musl
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
- target: x86_64-unknown-linux-musl
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Upload binary
uses: taiki-e/upload-rust-binary-action@v1
with:
bin: cargo-semver-checks
target: ${{ matrix.target }}
ref: refs/tags/${{ inputs.publish-tag }}
tar: all
zip: windows
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
CARGO_PROFILE_RELEASE_LTO: true
Loading