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

ci: update on-tag pypi release action #3078

Merged
merged 3 commits into from
Nov 5, 2024
Merged
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
62 changes: 9 additions & 53 deletions .github/workflows/test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
# It's not possible to condition steps on env or secrets,
# We need an explicit check here
if [ -n "$TWINE_USERNAME" -a -n "$TWINE_PASSWORD" ]; then
twine upload dist/*
twine upload --verbose dist/*
else
echo "::warning::Not uploading to test PyPI, no credentials available!"
fi
Expand All @@ -69,7 +69,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11, 3.12]
os: [ubuntu-latest, macos-latest, windows-latest]
dist: [wheel, sdist]
Copy link
Collaborator

Choose a reason for hiding this comment

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

'dist' might still be needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's in the previous matrix that I'm putting back, and it's used by the - name: Install wheel and - name: Install sdist steps


Expand Down Expand Up @@ -157,7 +157,7 @@ jobs:
# It's not possible to condition steps on env or secrets,
# We need an explicit check here
if [ -n "$TWINE_USERNAME" -a -n "$TWINE_PASSWORD" ]; then
twine upload dist/*
twine upload --verbose dist/*
else
echo "::warning::Not uploading to PyPI, no credentials available!"
fi
Expand All @@ -181,53 +181,9 @@ jobs:
path: dist/

- name: Upload dist files to release
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
tag = context.ref.split('/').pop()
console.log('running on:' + context.ref);
console.log('Looking for release for tag:' + tag);

var release
try {
release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tag
});
console.log('Release found at: ' + release.data.html_url); // '
} catch (err) {
if (err.status == 404) {
console.log('Release not found, creating a new one');
release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tag,
name: 'Release ' + tag,
body: 'New features and fixed bugs'
});
} else {
throw err;
}
}

console.log('Using release upload url: ' + release['data']['upload_url']);
// Determine content-length for header to upload asset
for (asset of ['${{ needs.create-python-dist.outputs.wheel }}', '${{ needs.create-python-dist.outputs.sdist }}']) {
const file_path = 'dist/' + asset;
const file_size = file_path => fs.statSync(file_path).size;
console.log('Uploading: ' + file_path);

// Setup headers for API call, see Octokit Documentation:
// https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information
const headers = { 'content-type': 'application/zip', 'content-length': file_size(file_path) };

// Upload a release asset
const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({
url: release.data.upload_url,
headers,
name: asset,
file: fs.readFileSync(file_path)
});
}
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
previous_release=$(gh --repo ${{ github.repository }} release list | head -n 1 | awk '{print $1}')
gh --repo ${{ github.repository }} release create --generate-notes --notes-start-tag "$previous_release" ${{ github.ref }} dist/*
Loading