Skip to content

Commit

Permalink
Bug: fix github upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanm101 committed Feb 15, 2025
1 parent 02e218a commit b9eda56
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
55 changes: 39 additions & 16 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ on:
push:
required: true
type: string

jobs:
publish-release:
if: ${{ startsWith(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
contents: write
id-token: write
steps:
- name: Checkout
Expand All @@ -34,26 +35,48 @@ jobs:
name: localllmrag
path: dist

- name: Upload an Asset in GitHub Release

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changes }}
draft: false
prerelease: false

- name: Upload Release Assets
uses: "actions/github-script@v6"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const fs = require('fs').promises;
await github.rest.repos.uploadReleaseAsset({
name: 'localllmrag-${{ inputs.tag }}.tar.gz',
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ env.RELEASE_ID }},
data: await fs.readFile('dist/*.tar.gz')
});
await github.rest.repos.uploadReleaseAsset({
name: 'localllmrag-${{ inputs.tag }}-py3-none-any.whl',
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ env.RELEASE_ID }},
data: await fs.readFile('dist/*.whl')
});
const path = require('path');
const files = await fs.readdir('dist');
const tarFile = files.find(file => file.endsWith('.tar.gz'));
const wheelFile = files.find(file => file.endsWith('.whl'));
for (const file of [tarFile, wheelFile]) {
if (!file) continue;
const filePath = path.join('dist', file);
const fileData = await fs.readFile(filePath);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.create_release.outputs.id }},
name: file,
data: fileData,
headers: {
'content-type': file.endsWith('.tar.gz') ?
'application/gzip' : 'application/x-wheel+zip',
}
});
}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: make test

- name: Build
run: make build
run: cat pyproject.toml | grep version && make build-release && cat pyproject.toml | grep version

- name: Upload artifact
if: matrix.python-version == env.python-upload-version
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test:
PYTHONPATH=$(PYTHONPATH) $(PYTHON) -m pytest tests

__version__:
sh scripts/setversion.sh
bash scripts/setversion.sh

build-release: __version__ build

Expand Down
4 changes: 2 additions & 2 deletions scripts/setversion.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash -xe
#!/usr/bin/env bash -xe

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
version=$(git describe --tags --always 2>/dev/null)

# Normalize version to be PEP 440-compliant
if [[ "$version" == *"-"* ]]; then
base_version=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//') # Remove leading "v" if present
commits_since_tag=$(git rev-list --count HEAD ^$base_version 2>/dev/null || echo 0)
commits_since_tag=$(git rev-list --count HEAD "^$base_version" 2>/dev/null || echo 0)
version="${base_version}.post${commits_since_tag}"
if [[ -z "$base_version" ]]; then
version="0.0.0"
Expand Down

0 comments on commit b9eda56

Please sign in to comment.