michaelb / sniprun

A neovim plugin to run lines/blocs of code (independently of the rest of the file), supporting multiples languages
MIT License
1.43k stars 46 forks source link

Fix release tag detection #243

Closed junkblocker closed 1 year ago

junkblocker commented 1 year ago

Without this fix it currently becomes

tag_to_fetch='This release and associated artifacts were created by Github Action. See the changelog [here](https://github.com/michaelb/sniprun/blob/master/CHANGELOG.md).'
michaelb commented 1 year ago

actually your command line doesn't appear to work on my machine (while the old one does), as there lacks a space in the grep expression:

'"tag_name":".*' -> '"tag_name": ".*'

on what kind of machine (OS/shell) do you run ? Most probably Linux/bash but who knows...(Could you provide me with more info about the initial command on your machine ? at least the different parts between each pipe and their respective output).

Also, I don't find a grep -o POSIX man page, which is an issue since this script aims to be POSIX-compliant (even if most sh are symlink to bash nowadays)

junkblocker commented 1 year ago

I am on Fedora Linux running it with bash. I believe grep -o is POSIX but we can do it with sed easily. Pushed a change.

michaelb commented 1 year ago

Could you provide me with more info about the initial command on your machine ? at least the different parts between each pipe and their respective output ?

curl ... -> {'blablablah'} curl .... | grep tag_name_regex -> "something" curl ... | grep | sed -> incorrect tag_to_fetch

I'd like to understand what's going wrong

junkblocker commented 1 year ago
remote_version=$(get_latest_release)
++ get_latest_release
++ curl --silent https://api.github.com/repos/michaelb/sniprun/releases/latest
++ grep '"tag_name":'
++ sed -E 's/.*"([^"]+)".*/\1/'
+ remote_version='This release and associated artifacts were created by Github Action. See the changelog [here](https://github.com/michaelb/sniprun/blob/master/CHANGELOG.md).'
michaelb commented 1 year ago

Well, sure but what i wanted to know was the output of these steps if you execute them 'manually'. I think the output of these two commands would be enough to allow me to understand what's going on.

curl --silent https://api.github.com/repos/michaelb/sniprun/releases/latest

curl --silent https://api.github.com/repos/michaelb/sniprun/releases/latest | grep '"tag_name":'

if you would be so inclined. Regardless, I think your contribution will have to be integrated because of the fact that the current script sometimes doesn't work. I'd just like to understand exactly how it fails.

could you also provide your version of curl ? (As maybe the output is formatted differently between version)

junkblocker commented 1 year ago

Ah, well the reason it fails is that previous code assumes the json is prettified while I am seeing a single long string without newlines. So grep gets the whole string and then sed breaks due to it being the whole json.

% curl --silent https://api.github.com/repos/michaelb/sniprun/releases/latest
{"url":"https://api.github.com/repos/michaelb/sniprun/releases/113184139","assets_url":"https://api.github.com/repos/michaelb/sniprun/releases/113184139/assets","upload_url":"https://uploads.github.com/repos/michaelb/sniprun/releases/113184139/assets{?name,label}","html_url":"https://github.com/michaelb/sniprun/releases/tag/v1.3.5","id":113184139,"author":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"node_id":"RE_kwDOES7YK84Gvw2L","tag_name":"v1.3.5","target_commitish":"master","name":"","draft":false,"prerelease":false,"created_at":"2023-07-22T09:08:49Z","published_at":"2023-07-22T09:10:37Z","assets":[{"url":"https://api.github.com/repos/michaelb/sniprun/releases/assets/118108427","id":118108427,"node_id":"RA_kwDOES7YK84HCjEL","name":"sniprun","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"binary/octet-stream","state":"uploaded","size":10406168,"download_count":803,"created_at":"2023-07-22T09:10:37Z","updated_at":"2023-07-22T09:10:38Z","browser_download_url":"https://github.com/michaelb/sniprun/releases/download/v1.3.5/sniprun"}],"tarball_url":"https://api.github.com/repos/michaelb/sniprun/tarball/v1.3.5","zipball_url":"https://api.github.com/repos/michaelb/sniprun/zipball/v1.3.5","body":"This release and associated artifacts were created by Github Action. See the changelog [here](https://github.com/michaelb/sniprun/blob/master/CHANGELOG.md)."}%

% curl --silent https://api.github.com/repos/michaelb/sniprun/releases/latest | grep '"tag_name":"'
{"url":"https://api.github.com/repos/michaelb/sniprun/releases/113184139","assets_url":"https://api.github.com/repos/michaelb/sniprun/releases/113184139/assets","upload_url":"https://uploads.github.com/repos/michaelb/sniprun/releases/113184139/assets{?name,label}","html_url":"https://github.com/michaelb/sniprun/releases/tag/v1.3.5","id":113184139,"author":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"node_id":"RE_kwDOES7YK84Gvw2L","tag_name":"v1.3.5","target_commitish":"master","name":"","draft":false,"prerelease":false,"created_at":"2023-07-22T09:08:49Z","published_at":"2023-07-22T09:10:37Z","assets":[{"url":"https://api.github.com/repos/michaelb/sniprun/releases/assets/118108427","id":118108427,"node_id":"RA_kwDOES7YK84HCjEL","name":"sniprun","label":"","uploader":{"login":"github-actions[bot]","id":41898282,"node_id":"MDM6Qm90NDE4OTgyODI=","avatar_url":"https://avatars.githubusercontent.com/in/15368?v=4","gravatar_id":"","url":"https://api.github.com/users/github-actions%5Bbot%5D","html_url":"https://github.com/apps/github-actions","followers_url":"https://api.github.com/users/github-actions%5Bbot%5D/followers","following_url":"https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}","gists_url":"https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}","starred_url":"https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/github-actions%5Bbot%5D/subscriptions","organizations_url":"https://api.github.com/users/github-actions%5Bbot%5D/orgs","repos_url":"https://api.github.com/users/github-actions%5Bbot%5D/repos","events_url":"https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}","received_events_url":"https://api.github.com/users/github-actions%5Bbot%5D/received_events","type":"Bot","site_admin":false},"content_type":"binary/octet-stream","state":"uploaded","size":10406168,"download_count":803,"created_at":"2023-07-22T09:10:37Z","updated_at":"2023-07-22T09:10:38Z","browser_download_url":"https://github.com/michaelb/sniprun/releases/download/v1.3.5/sniprun"}],"tarball_url":"https://api.github.com/repos/michaelb/sniprun/tarball/v1.3.5","zipball_url":"https://api.github.com/repos/michaelb/sniprun/zipball/v1.3.5","body":"This release and associated artifacts were created by Github Action. See the changelog [here](https://github.com/michaelb/sniprun/blob/master/CHANGELOG.md)."}%

% curl --version
curl 8.0.1 (x86_64-redhat-linux-gnu) libcurl/8.0.1 OpenSSL/3.0.9 zlib/1.2.13 brotli/1.0.9 libidn2/2.3.4 libpsl/0.21.2 (+libidn2/2.3.4) libssh/0.10.5/openssl/zlib nghttp2/1.52.0
Release-Date: 2023-03-20
Protocols: dict file ftp ftps gopher gophers http https imap imaps ldap ldaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM NTLM_WB PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets
michaelb commented 1 year ago

Ok, thanks for the clarification

I'll merge your contribution momentarily, many thanks !