-
-
Notifications
You must be signed in to change notification settings - Fork 33
Add release-assets action
#61
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: 'Home Assistant helper: release-assets' | ||
| description: 'GitHub action helper: release-assets' | ||
| inputs: | ||
| github-token: | ||
| description: GITHUB_TOKEN with 'contents' write permission | ||
| required: true | ||
| folder: | ||
| description: Folder for distribution packages | ||
| required: false | ||
| default: "dist/" | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Fail if not release event | ||
| if: github.event_name != 'release' | ||
| shell: bash | ||
| run: | | ||
| echo "Action can only be run for 'release' events" | ||
| echo "Current event_name: ${{ github.event_name }}" | ||
| exit 1 | ||
| - name: Get build file names | ||
| id: file-names | ||
| shell: bash | ||
| run: | | ||
| echo "::set-output name=sdist::$(ls ${{ inputs.folder }} | grep '.*.tar.gz' | tail -n 1)" | ||
| echo "::set-output name=wheel::$(ls ${{ inputs.folder }} | grep '.*.whl' | tail -n 1)" | ||
| - name: Check for existing assets | ||
| id: existing-assets | ||
| shell: bash | ||
| run: | | ||
| API_REQUEST=$(curl -sS \ | ||
| -H "Accept: application/vnd.github.v3+json" \ | ||
| ${{ github.event.release.assets_url }}) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to use authentication when accessing the GitHub API so this does not randomly fail due to rate-limits. |
||
| FOUND_ASSETS=$(echo $API_REQUEST | jq ".[] .name") | ||
| printf "Found release assets:\n$FOUND_ASSETS\n" | ||
| if [[ $FOUND_ASSETS == *"${{ steps.file-names.outputs.sdist }}"* ]]; then | ||
| echo "::set-output name=sdist-found::true" | ||
| fi | ||
| if [[ $FOUND_ASSETS == *"${{ steps.file-names.outputs.wheel }}"* ]]; then | ||
| echo "::set-output name=wheel-found::true" | ||
| fi | ||
| - name: Upload release asset (sdist) | ||
| if: ${{ !steps.existing-assets.outputs.sdist-found }} | ||
| uses: actions/upload-release-asset@v1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This action is archived https://github.com/actions/upload-release-asset and unmaintained. |
||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||
| with: | ||
| upload_url: ${{ github.event.release.upload_url }} | ||
| asset_path: ${{ inputs.folder }}${{ steps.file-names.outputs.sdist }} | ||
| asset_name: ${{ steps.file-names.outputs.sdist }} | ||
| asset_content_type: application/gzip | ||
| - name: Upload release asset (wheel) | ||
| if: ${{ !steps.existing-assets.outputs.wheel-found }} | ||
| uses: actions/upload-release-asset@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ inputs.github-token }} | ||
| with: | ||
| upload_url: ${{ github.event.release.upload_url }} | ||
| asset_path: ${{ inputs.folder}}${{ steps.file-names.outputs.wheel }} | ||
| asset_name: ${{ steps.file-names.outputs.wheel }} | ||
| asset_content_type: application/zip | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
echo "::error::[message]so it's properly displayed in the UI.