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

Improve release workflow #61

Merged
merged 3 commits into from
Jul 1, 2024
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
63 changes: 35 additions & 28 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@ name: Release
on:
push:
tags:
- v*
- "v*.*.*"

jobs:
create-release:
name: Create Release
check-release-version:
name: Check Release Version
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true
prerelease: false
python-version: "3.x"

- name: Check tag version against cargo version
run: python check_version.py ${{ github.ref_name }}

build:
needs: ["create-release"]
needs: ["check-release-version"]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -60,7 +55,6 @@ jobs:
shell: bash
run: |
echo "PROJECT_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "Version is ${{ env.PROJECT_VERSION }}"

- name: Rust
run: rustup toolchain install stable-${{ matrix.target }} --profile minimal --no-self-update
Expand Down Expand Up @@ -89,24 +83,37 @@ jobs:
zip ../release.zip *
fi

- name: Upload Archive to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: release.zip
asset_name: ${{ env.BIN }}-${{ env.PROJECT_VERSION }}-${{ matrix.label }}.zip
asset_content_type: application/octet-stream

- name: Upload Archive to Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ env.BIN }}-${{ env.PROJECT_VERSION }}-${{ matrix.label }}.zip
path: release.zip

publish:
create-release:
needs: ["build"]
name: Create Release
runs-on: ubuntu-latest
steps:
- name: Create artifact directory
shell: bash
run: mkdir gh_artifacts

- name: Download artifacts
id: download-artifact
uses: dawidd6/action-download-artifact@v6
with:
path: gh_artifacts

- name: Create release
id: create_release
uses: softprops/action-gh-release@v2
with:
draft: true
generate_release_notes: true
files: gh_artifacts/*.zip

publish:
needs: ["create-release"]
name: Publish
runs-on: ubuntu-latest
steps:
Expand Down
35 changes: 35 additions & 0 deletions check_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import sys

def main():
if len(sys.argv) <= 1:
print("missing version argument", file=sys.stderr)
exit(1)

version = sys.argv[1]
cargo_version = ""
found_cargo_version = False
matched_version = False

# Find first occurrence of "version = x.y.z" and assume that as the project version:
with open("Cargo.toml", mode="r") as cargo_file:
lines = cargo_file.readlines()
for line in lines:
pair = line[:-1].split(sep="=")
if len(pair) == 2 and pair[0].strip() == "version":
cargo_version = "v" + pair[1].strip()[1:-1]
matched_version = cargo_version == version
found_cargo_version = True
break

if not found_cargo_version:
print("failed to find cargo version", file=sys.stderr)
exit(1)

if not matched_version:
print(f"version mismatch (input: {version} | cargo: {cargo_version})", file=sys.stderr)
exit(1)

print("versions matched")

if __name__ == "__main__":
main()