Sheriffing/How To/Helpers: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(added mach file-info bugzilla-component lookup shortcut (mfi))
 
(drop code for mfi command because Treeherder autosuggests Bugzilla product and component, add command prompt code for macOS / zsh)
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
= Helpers =
{{Sheriffing How To|Helpers}}
== mach file-info bugzilla-component lookup shortcut (mfi) ==
= Command Line =
If the bugzilla product and component for a file or folder have to be looked up on Linux, provide the file name, folder name, the path or only a part of any of this to retrieve this information with
<pre>mfi search_term</pre>
while in the root folder of the mozilla-unified repository.


* In your home directory, check if there is a file called <code>.bash_aliases</code>.
== Terminating many tasks from the command line ==
* If not, create it, e.g. with the file manager: menu 'File' > 'New Document'.
If many tasks need to be terminated, e.g. because there is a backlog of gecko-decision-task (and canceling them from Treeherder also uses gecko-decision-task), this can be done with the taskcluster command line client like this:
* Add the following code:
* Run <code>export TASKCLUSTER_ROOT_URL=https://firefox-ci-tc.services.mozilla.com</code>
* Sign in: <code>eval `taskcluster signin`</code>
* Log in in the browser, close the browser after you clicked 'Create Client'.
* Get the list of taskcluster task ids which need to be terminated, e.g. from https://sql.telemetry.mozilla.org (create query, run it, download result as .csv file).
* In a text editor, create a line for each task like <code>taskcluster task cancel GcyOUlbLQhGSy4LU3paGTA</code> with <code>GcyOUlbLQhGSy4LU3paGTA</code> replaced by the task id. E.g. in Notepad++, paste the task ids, select the position left of the first character for each line by positioning the cursor at the start of the file and then selecting the positions with Alt + Shift + click into the first position of the last line and then typing <code>taskcluster task cancel </code>.
* Save the content as <code>cancel.sh</code> file.
* Set it as executable with <code>chmod +x cancel.sh</code>.
* Run it with <code>./cancel.sh</code>.
Successful cancellations are indicated by `exception 'canceled'`.
 
 
== Active tree in command line prompt ==
Let the command line prompt which tree was active when the last command finished, how many patches are applied locally and if there are uncommitted changes (including files not tracked by version control).
 
=== Linux (bash) ===
* In your home directory, open the file called <code>.bashrc</code>.
* Find this line <pre>unset color_prompt force_color_prompt</pre>
* After that add the following code:
<pre>
<pre>
mfi() {
hg_info() {
     ./mach file-info bugzilla-component `find -path "*$1*" -not -path "./.hg/*"`
     declare tipRevision=`hg log -r . -T {node} 2> /dev/null`
    if [ "$tipRevision" == '' ];then
        echo ''
        return
    fi
    declare fxheads=`hg fxheads -T '{label("log.changeset", node)} {label("log.tag", join(fxheads, "+"))}\n' 2> /dev/null`
    declare shortestDistance=-2 # Not found
    declare shortestDistanceTrees=''
    while read -r line; do
        IFS=', ' read -r -a array <<< "$line"
        declare headRevision=${array[0]}
        declare headTrees=${array[1]}
        declare distance=`hg log -r $headRevision::. --template x | wc -c`
        declare distance=$((distance-1))
        if [ "$distance" -gt -1 ];then
            if [ "$shortestDistance" -eq -2 ];then
                declare shortestDistance=$distance
                declare shortestDistanceTrees=$headTrees
            elif [ "$distance" -lt "$shortestDistance" ];then
                    declare shortestDistance=$distance
                    declare shortestDistanceTrees=$headTrees
            fi
        fi
    done <<< "$fxheads"
    # echo "shortest distance for $shortestDistanceTrees with distance $shortestDistance"
    declare bash_string=''
    if [ "$shortestDistanceTrees" == '' ];then
        declare bash_string=' (?'
    else
        declare bash_string=' '$shortestDistanceTrees
        if [ "$shortestDistance" -eq 0 ];then
            declare bash_string=$bash_string'(0'
        else
            declare bash_string=$bash_string'(+'$shortestDistance''
        fi
    fi
    declare uncommitChanges=`hg status`
    if [ "$uncommitChanges" == '' ];then
        declare bash_string=$bash_string')'
    else
        declare bash_string=$bash_string'+changes)'
    fi
    echo "$bash_string"
}
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(hg_info)\[\033[00m\] $ "
</pre>
</pre>
* Save and close the file.
* Save and close the file.
* '''New''' console windows will be support the '''mfi''' command to find matching files and check for their bugzilla products and components. If it doesn't find matches, error messages are shown.
'''New''' console windows will show the active tree, the number of patches applied locally and untracked changes including files not tracked by version control (e.g. .rej files from a conflict).
Example: <pre>user@VirtualBox ~/mozilla/mozilla-unified beta(+2+changes) $</pre>
The active repository is '''beta''', there are '''2 local commits''' and '''untracked changes''' (more information about those with '''hg status''').


Examples:
If you pulled new changes from the server but didn't update the active repository to those, the script will try to find a different tree for which the working directory has all the changesets and e.g. show a big number of changesets for the tree due to that (e.g. <code>central(+67)</code>) or a question mark if it finds no tree fulfilling that condition (<code>(?)</code>).


File name
=== macOS (zsh) ===
<pre>$ mfi browser_treeupdate_canvas.js
* In your home directory, check if the file <code>.zshrc</code> exists (file manager must show hidden files starting with ".").
Core :: Disability Access APIs
* If it is missing, create a text file with that name.
  accessible/tests/browser/e10s/browser_treeupdate_canvas.js
* Open the <code>.zshrc</code> file.
</pre>
* Append the following code to the file's content:
<pre>
setopt PROMPT_SUBST
 
function hg_info() {
    declare tipRevision=`hg log -r . -T {node} 2> /dev/null`
    if [[ -z "$tipRevision" ]];then
        echo ''
        return
    fi
    declare fxheads=`hg fxheads -T '{label("log.changeset", node)} {label("log.tag", join(fxheads, "+"))}\n' 2> /dev/null`
    declare shortestDistance=-2 # Not found
    declare shortestDistanceTrees=''
    while read -r line; do
        IFS=', ' read -r -A array <<< "$line"
        declare headRevision=${array[1]}
        declare headTrees=${array[2]}
        declare distance=`hg log -r $headRevision::. --template x | wc -c`
        declare distance=$((distance-1))
        if [[ "$distance" -gt -1 ]];then
            if [[ "$shortestDistance" -eq -2 ]];then
                declare shortestDistance=$distance
                declare shortestDistanceTrees=$headTrees
            elif [[ "$distance" -lt "$shortestDistance" ]];then
                    declare shortestDistance=$distance
                    declare shortestDistanceTrees=$headTrees
            fi
        fi
    done <<< "$fxheads"
    # echo "shortest distance for $shortestDistanceTrees with distance $shortestDistance"
    declare bash_string=''
    if [[ "$shortestDistanceTrees" == '' ]];then
        declare bash_string=' (?'
    else
        declare bash_string=' '$shortestDistanceTrees
        if [[ "$shortestDistance" -eq 0 ]];then
            declare bash_string=$bash_string'(0'
        else
            declare bash_string=$bash_string'(+'$shortestDistance''
        fi
    fi
    declare uncommitChanges=`hg status`
    if [[ -z "$uncommitChanges" ]];then
        declare bash_string=$bash_string')'
    else
        declare bash_string=$bash_string'+changes)'
    fi
    echo "$bash_string"
}


Part of file name
export PROMPT='%n@%m %F{green}%~%F{yellow}$(hg_info)%F{white} %# '
<pre>$ mfi treeupdate_canvas.js
Core :: Disability Access APIs
  accessible/tests/browser/e10s/browser_treeupdate_canvas.js
</pre>
</pre>
* In the console terminal, run the following command to reload the behavior of command prompt: <code>source ~/.zshrc</code>
The console should show the active tree, the number of patches applied locally and untracked changes including files not tracked by version control (e.g. .rej files from a conflict).
Example: <pre>user@VirtualBox ~/mozilla/mozilla-unified beta(+2+changes) $</pre>
The active repository is '''beta''', there are '''2 local commits''' and '''untracked changes''' (more information about those with '''hg status''').


Folder name
If you pulled new changes from the server but didn't update the active repository to those, the script will try to find a different tree for which the working directory has all the changesets and e.g. show a big number of changesets for the tree due to that (e.g. <code>central(+67)</code>) or a question mark if it finds no tree fulfilling that condition (<code>(?)</code>).
<pre>$ mfi accessible/tests/browser/
Core :: Disability Access APIs
  accessible/tests/browser/.eslintrc.js
  accessible/tests/browser/bounds
  ...
  accessible/tests/browser/tree/browser_aria_owns.js
  accessible/tests/browser/tree/head.js
</pre>

Latest revision as of 11:11, 13 October 2021

Command Line

Terminating many tasks from the command line

If many tasks need to be terminated, e.g. because there is a backlog of gecko-decision-task (and canceling them from Treeherder also uses gecko-decision-task), this can be done with the taskcluster command line client like this:

  • Run export TASKCLUSTER_ROOT_URL=https://firefox-ci-tc.services.mozilla.com
  • Sign in: eval `taskcluster signin`
  • Log in in the browser, close the browser after you clicked 'Create Client'.
  • Get the list of taskcluster task ids which need to be terminated, e.g. from https://sql.telemetry.mozilla.org (create query, run it, download result as .csv file).
  • In a text editor, create a line for each task like taskcluster task cancel GcyOUlbLQhGSy4LU3paGTA with GcyOUlbLQhGSy4LU3paGTA replaced by the task id. E.g. in Notepad++, paste the task ids, select the position left of the first character for each line by positioning the cursor at the start of the file and then selecting the positions with Alt + Shift + click into the first position of the last line and then typing taskcluster task cancel .
  • Save the content as cancel.sh file.
  • Set it as executable with chmod +x cancel.sh.
  • Run it with ./cancel.sh.

Successful cancellations are indicated by `exception 'canceled'`.


Active tree in command line prompt

Let the command line prompt which tree was active when the last command finished, how many patches are applied locally and if there are uncommitted changes (including files not tracked by version control).

Linux (bash)

  • In your home directory, open the file called .bashrc.
  • Find this line
    unset color_prompt force_color_prompt
  • After that add the following code:
hg_info() {
    declare tipRevision=`hg log -r . -T {node} 2> /dev/null`
    if [ "$tipRevision" == '' ];then
        echo ''
        return
    fi
    declare fxheads=`hg fxheads -T '{label("log.changeset", node)} {label("log.tag", join(fxheads, "+"))}\n' 2> /dev/null`
    declare shortestDistance=-2 # Not found
    declare shortestDistanceTrees=''
    while read -r line; do
        IFS=', ' read -r -a array <<< "$line"
        declare headRevision=${array[0]}
        declare headTrees=${array[1]}
        declare distance=`hg log -r $headRevision::. --template x | wc -c`
        declare distance=$((distance-1))
        if [ "$distance" -gt -1 ];then
            if [ "$shortestDistance" -eq -2 ];then
                declare shortestDistance=$distance
                declare shortestDistanceTrees=$headTrees
            elif [ "$distance" -lt "$shortestDistance" ];then
                    declare shortestDistance=$distance
                    declare shortestDistanceTrees=$headTrees
            fi
        fi
    done <<< "$fxheads"
    # echo "shortest distance for $shortestDistanceTrees with distance $shortestDistance"
    declare bash_string=''
    if [ "$shortestDistanceTrees" == '' ];then
        declare bash_string=' (?'
    else
        declare bash_string=' '$shortestDistanceTrees
        if [ "$shortestDistance" -eq 0 ];then
            declare bash_string=$bash_string'(0'
        else
            declare bash_string=$bash_string'(+'$shortestDistance''
        fi
    fi
    declare uncommitChanges=`hg status`
    if [ "$uncommitChanges" == '' ];then
        declare bash_string=$bash_string')'
    else
        declare bash_string=$bash_string'+changes)'
    fi
    echo "$bash_string"
}

export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(hg_info)\[\033[00m\] $ "
  • Save and close the file.

New console windows will show the active tree, the number of patches applied locally and untracked changes including files not tracked by version control (e.g. .rej files from a conflict).

Example:

user@VirtualBox ~/mozilla/mozilla-unified beta(+2+changes) $

The active repository is beta, there are 2 local commits and untracked changes (more information about those with hg status).

If you pulled new changes from the server but didn't update the active repository to those, the script will try to find a different tree for which the working directory has all the changesets and e.g. show a big number of changesets for the tree due to that (e.g. central(+67)) or a question mark if it finds no tree fulfilling that condition ((?)).

macOS (zsh)

  • In your home directory, check if the file .zshrc exists (file manager must show hidden files starting with ".").
  • If it is missing, create a text file with that name.
  • Open the .zshrc file.
  • Append the following code to the file's content:
setopt PROMPT_SUBST

function hg_info() {
    declare tipRevision=`hg log -r . -T {node} 2> /dev/null`
    if [[ -z "$tipRevision" ]];then
        echo ''
        return
    fi
    declare fxheads=`hg fxheads -T '{label("log.changeset", node)} {label("log.tag", join(fxheads, "+"))}\n' 2> /dev/null`
    declare shortestDistance=-2 # Not found
    declare shortestDistanceTrees=''
    while read -r line; do
        IFS=', ' read -r -A array <<< "$line"
        declare headRevision=${array[1]}
        declare headTrees=${array[2]}
        declare distance=`hg log -r $headRevision::. --template x | wc -c`
        declare distance=$((distance-1))
        if [[ "$distance" -gt -1 ]];then
            if [[ "$shortestDistance" -eq -2 ]];then
                declare shortestDistance=$distance
                declare shortestDistanceTrees=$headTrees
            elif [[ "$distance" -lt "$shortestDistance" ]];then
                    declare shortestDistance=$distance
                    declare shortestDistanceTrees=$headTrees
            fi
        fi
    done <<< "$fxheads"
    # echo "shortest distance for $shortestDistanceTrees with distance $shortestDistance"
    declare bash_string=''
    if [[ "$shortestDistanceTrees" == '' ]];then
        declare bash_string=' (?'
    else
        declare bash_string=' '$shortestDistanceTrees
        if [[ "$shortestDistance" -eq 0 ]];then
            declare bash_string=$bash_string'(0'
        else
            declare bash_string=$bash_string'(+'$shortestDistance''
        fi
    fi
    declare uncommitChanges=`hg status`
    if [[ -z "$uncommitChanges" ]];then
        declare bash_string=$bash_string')'
    else
        declare bash_string=$bash_string'+changes)'
    fi
    echo "$bash_string"
}

export PROMPT='%n@%m %F{green}%~%F{yellow}$(hg_info)%F{white} %# '
  • In the console terminal, run the following command to reload the behavior of command prompt: source ~/.zshrc

The console should show the active tree, the number of patches applied locally and untracked changes including files not tracked by version control (e.g. .rej files from a conflict).

Example:

user@VirtualBox ~/mozilla/mozilla-unified beta(+2+changes) $

The active repository is beta, there are 2 local commits and untracked changes (more information about those with hg status).

If you pulled new changes from the server but didn't update the active repository to those, the script will try to find a different tree for which the working directory has all the changesets and e.g. show a big number of changesets for the tree due to that (e.g. central(+67)) or a question mark if it finds no tree fulfilling that condition ((?)).