Skip to content

Commit

Permalink
Improve release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleitnick committed Jul 1, 2024
1 parent c421fc7 commit bc7554b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 27 deletions.
61 changes: 34 additions & 27 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@ on:
- 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: Check Release Version
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()

0 comments on commit bc7554b

Please sign in to comment.