GitHub Tag Message Markdown - bash

How do I make a tag commit/push message show up as markdown on GitHub?
The closest I’ve seen is someone suggesting to make a custom script defining the “body”

#VonC, that is good where gh is available, however, I'm in an environment where it's not... as such, I created the following bash script using the api. (clearly all below $vars need to be either defined or substituted for working example)
COMMIT_BODY can be markdown (e.g. COMMIT_BODY="**This is markdow**")
res=`curl --user "$USERNAME:$TOKEN" -X POST https://api.github.com/repos/${ORGANIZATION}/${REPO}/releases \
-d "
{
\"tag_name\": \"$VERSION\",
\"target_commitish\": \"$BRANCH\",
\"name\": \"$VERSION\",
\"body\": \"$COMMIT_BODY\",
\"draft\": false,
\"prerelease\": false
}"`

You could try and use the GitHub CLI gh (after installation, and login), and its gh release create command in order to pass a markdown file as release notes.
gh release create v1.2.3 -F changelog.md
That would do it all: tag, message tag, release notes and publication of said release to GitHub.
Right from your local workstation/repository.

Related

How to modify documentation built with sphinx via a script in readthedocs build

I am trying to run a script to modify the documentation built by sphinx hosted by Read the Docs (because some links are not properly handled). The script works when I try to build it locally, but either fails on the Read the Docs build or the changes do not get propagated to the web site.
The script I'm trying to run is super simple, it replaces some html links that are not properly converted by sphinx-markdown-tables:
#!/bin/bash
# fix_table_links.sh
FILE="_build/html/api_reference.html"
if [[ "$1" != "" ]]; then
FILE="$1"
fi
sed -E 's/a href="(.*)\.md"/a href="\1\.html"/g' -i ${FILE}
My readthedocs.yml looks like this:
# Required
version: 2
# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
# Optionally build your docs in additional formats such as PDF and ePub
formats: all
# Optionally set the version of Python and requirements required to build your docs
python:
install:
- requirements: docs/requirements.readthedocs.txt
build:
os: ubuntu-20.04
tools:
python: "3.8"
jobs:
post_build:
- echo "Running post-build commands."
- bash docs/fix_table_links.sh _readthedocs/html/api_reference.html
There are two cases:
Case 1) Using the readthedocs.yml as above, the build fails because _readthedocs/html/api_reference.html does not exist, despite this directory being the place the documentation claims will get uploaded from here. An example failure of this run is here.
Case 2) If I change the final of readthedocs.yml to bash docs/fix_table_links.sh docs/_build/html/api_reference.html, then the build passes (example here). But the links are not updated on the Read the Docs site: they still point to markdown pages rather than their corresponding HTML pages, so it must not be the version that gets uploaded to the Read the Docs web site.
Wading through documentation, I can't figure out how do this. Has anybody done this before or have a better grasp on how Read the Docs builds work? Thanks!
If you're willing to rewrite the script as a Python function, then you can do this super easily by connecting it as an event handler for the build-finished event.
I've done something similar in one of my own repos, except I post-process a .rst file. It's not actually used on RTD, but I can see it works in the build logs. So it should work to post-process your HTML files as well, since the build-finished event would occur after they've been generated.
First, define the script as a function in your conf.py. It needs to have app and exception as parameters.
def replace_html_links(app, exception):
with open(FILE, 'r') as f:
html = f.read()
# stuff to edit and save the html
Then either define or add to your setup function:
def setup(app):
app.connect('build-finished', replace_html_links)
And that's it!

File is not `gofmt`-ed with `-s`: why is this happening and how to resolve it?

We use a linter (for Golang) that run through a Github Actions workflow every time we open or update a Pull Request on our repository.
It recently started to return the following error:
File is not `gofmt`-ed with `-s` (gofmt)
After what happened in this other PR to the file pkg/api/api/go.
(EDIT: link added to evaluate and eventually reproduce the error)
Evidences:
I would like to understand what was the source of this error, as well as how to resolve it?
Source of the error
It seems this error can be returned when the file is not properly formatted according to Go rules.
For example: If you accidentally used tab indentation rather than spaces.
EDIT: blackgreen's answer gives more accurate details about the source of the error
How to resolve it
You can use the following Go command:
gofmt -s -w <path_to_file>.go
... then commit the code.
Note that in my case: gofmt -w pkg/api/api.go was enough to resolve the problem (without the -s flag, which I found strange as the error specifically asked for the -s).
Source 1 + Source 2
The -s flag in gofmt has nothing to do with formatting. It's about simplifying the code:
Try to simplify code (after applying the rewrite rule, if any).
The warning you see comes from the linter golangci-lint. Since you claim to have fixed the error by running gofmt -w, the presence of the hint "with -s" may be due to this bug: https://github.com/golangci/golangci-lint/issues/513.
The linked issue was fixed in 2019 and released with v1.17.0. You might want to check if your pipeline is using an older version.
Assuming that your file pkg/api/api.go triggered the warning just because it was not formatted, gofmt -w solves the issue because -w overwrites the file:
If a file's formatting is different from gofmt's, overwrite it with gofmt's version.

Enabling the `todo` feature in sphinx docs

I am trying to use todo feature, I found a link on sphinx-docs and the following syntax
.. todo::
but it says that I need to set the todo_include_todos to True, as by default it is False, which file I need to update to get in enabled?
I found another SO post Sphinx todo box not showing but don't think it mentions the file where I need to set the config.
sphinx.ext.todo is a Sphinx extension which can be enabled by adding it to the list of extensions in your conf.py:
extensions = [
'extname',
'sphinx.ext.todo',
]
Once enabled, you need to configure it by setting the value todo_include_todos to True, also in your conf.py:
# Display todos by setting to True
todo_include_todos = True
Theme support for todos varies.
See also http://www.sphinx-doc.org/en/stable/config.html#confval-extensions
Note that the configuration option can also be overridden on the command line, which may make it easier to quickly expose or hide "to do"s according to the target audience. I believe booleans have to be passed as 0 or 1 in this case...
sphinx-build -b html -D todo_include_todos=1 -c docs docs build/html
or
python -m sphinx -b html -D todo_include_todos=1 -c docs docs build/html

bash use ruby code and save as variable

my end goal is to parse a visual studio team services ssh git url and use it to clone origin and my fork. I'm in windows and I use git bash I've made a few shell scripts to help me to clone it. Before when we used gitweb it was easy for me to parse as I could either run git_clone myproject or git_clone myproject.git or git_clone git://ourgitserver.ourcompany.com/myproject.git and the script would clone the above as origin and also add a remote with my user name in the form of ssh://git#outgitserver.ourcompany.com/myproject.git (and it handled name spaces well too). Well we started using vsts and I want to do the same thing.
The git_clone method changed a few times because of how people would tell/im/email me the link for the git project. I wanted to be able to just copy and paste it with minimal changes. thus far I have a simple git_vsts_close which requires two parameters the name of the project and the name of the repository. (in gitweb we would reference the namespace as vsts's project and the project would be vsts's repository). For the time being I'd like to take either the ssh url or the two parameters and do all the git things. in brief this is what i have so far
function git_vsts_clone {
local projectName=$1
local repositoryName=$2
if MISSING_ARG "usage: git_vsts_clone <project name> <repositoryName>\n projectName must be provided\n repositoryName must be provided" $projectName; then return 1; fi;
if MISSING_ARG "usage: git_vsts_clone <project name> <repositoryName>\n projectName must be provided\n repositoryName must be provided" $repositoryName; then return 1; fi;
local gitServer="ssh://mycompany#vs-ssh.visualstudio.com:22/${projectName}/_ssh/${repositoryName}"
local clonePath="/c/git/${projectName}/${repositoryName}"
local user_name=${USER:-${USERNAME}}
if [ ! -d $clonePath ]; then
INFO "Cloning $gitServer"
git clone $gitServer $clonePath || { ERROR "ERROR cloning $gitServer"; return 1;}
pushd $clonePath
INFO "Updating Submodules (gsui)"
git submodule update --init
INFO "adding user fork ${user_name}"
git remote add $user_name $gitServer.$user_name
git fetch $user_name
popd
INFO "Opening $clonePath in vscode"
fi
code $clonePath
}
last time when I tried to parse a url in bash I struggled with the whole split an item into an array. so I decided i'd try to use ruby (since it has a easy split method) so i've tried things like
$ gitServer='ssh://mycompany#vs-ssh.visualstudio.com:22/someProject/_ssh/myRepo'
$ ruby -e "a = '$gitServer'; b=a.split('/'); p b"
["ssh:", "", "mycompany#vs-ssh.visualstudio.com:22", "someProject", "_ssh", "myRepo"]
$ foo=`ruby -e "a = '$gitServer'; b=a.split('/'); p b"`
$ echo "${c[3]}"
$ echo "${c[0]}"
["ssh:", "", "mycompany#vs-ssh.visualstudio.com:22", "someProject", "_ssh", "myRepo"]
so I dunno. I don't have to use ruby it just seemed like a easy solution... now not so much. So how can I get the project and repository name out of the url in either bash or bash using ruby?
Here is a way you can get the values into environment variables using Ruby:
Assuming you have a URL environment variable containing the git repo url, such as created by the line below:
export URL='ssh://mycompany#vs-ssh.visualstudio.com:22/someProject/_ssh/myRepo'
You can do the following to put your desired values into other environment variables:
export PROJECT=`ruby -e "puts ENV['URL'].split('/')[3]"`
export REPO_NAME=`ruby -e "puts ENV['URL'].split('/')[5]"`

Cucumber tags running even when excluded (I think)

This is what I am typing in cygwin:
cucumber.bat features -p super
This is the super profile:
super: FIG_NEWTON_FILE=local.yml --no-source --color --tags ~#nonsuper,~#unimplemented --format pretty
This is an example of a test I want to skip:
#nonsuper
Scenario: Try to set denial specials
Then the "Denial Specialist" field is disabled at the "summary" view
It is running scenarios and features with those tags.
I believe I've done something wrong in the profile, I just can't figure out what.
Thanks for any help =]
When you do:
--tags ~#nonsuper,~#unimplemented
It means to run scenarios without the tag #nonsuper OR without the tag #unimplemented. Your scenario meets the requirement of not having the #unimplemented tag, therefore it gets run.
What you want is:
--tags ~#nonsuper --tags ~#unimplemented
This means to run scenarios without the tag #nonsuper AND without the tag #unimplemented.
For more details on combining tags see the tags portion of the Cucumber wiki.
if you want to skip a scenario just put
#wip
tag in place of '#nonsuper'

Resources