﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
20146	Trigger macOS re-build on github when changeset marked at tested	Stereo	stoecker	"This is a work in progress, intended to run on the josm server when releasing a new 'tested' version. Instead of triggering a new macOS build locally like in the past, this finds the github action workflow that contained `git-svn-id: https://josm.openstreetmap.de/svn/trunk@$josm_revision` in its commit message.

When a git action run is triggered, it fetches https://josm.openstreetmap.de/tested. If /tested has been properly updated before triggering the rebuild, it will build as a release instead of a pre-release, like https://github.com/grischard/josm/releases/tag/17329-tested

The shell script requires jq to parse the github json.

I've never seen what the build process looks like behind the curtain on the josm server - will this work? Comments and improvements very welcome.


{{{#!shell

#!/bin/bash

set -Eeuo pipefail
# Don't leak my tokens
set +x
# Don't glob
set -f

if [ -z ""${1-}"" ]; then
    echo ""Usage: $0 josm_revision""
    echo ""For example: $0 17329""
    exit 1
else
    josm_revision=""${1-}""
fi

github_repo='openstreetmap/josm'
# Grab yours for free today exclusively at https://github.com/settings/tokens
github_oauth_token='invalidtoken'

if [[ ""$josm_revision"" == ""$(curl --silent https://josm.openstreetmap.de/tested)"" ]]; then
    echo ""$josm_revision is indeed the current tested release.""
else
    echo ""Be careful: $josm_revision is not the current tested release at https://josm.openstreetmap.de/tested.""
fi

# echo ""Fetching re-run url for $josm_revision from past actions in $github_repo""

if rerun_url=""$(
    curl \
        --silent \
        --fail \
        --header 'Accept: application/vnd.github.v3+json' \
        --header ""Authorization: token $github_oauth_token"" \
        --header 'Content-Type: application/json' \
        https://api.github.com/repos/$github_repo/actions/runs |
        jq \
            --raw-output \
            --arg JOSM_REVISION ""$josm_revision"" \
            '.[""workflow_runs""] | .[] | select(.head_commit.message | contains(""\n\ngit-svn-id: https://josm.openstreetmap.de/svn/trunk@"" + $JOSM_REVISION)) | .rerun_url'
)""; then
    if [ -z ""$rerun_url"" ]; then
        echo >&2 ""Could not get rerun_url for commit matching $1 in $github_repo. Have a look at https://api.github.com/repos/$github_repo/actions/runs""
        exit 1
    else
        # echo ""I got $rerun_url which I will now request""
        if test ""$(
            curl \
                --silent \
                --fail \
                -X POST \
                --header 'Accept: application/vnd.github.v3+json' \
                --header ""Authorization: token $github_oauth_token"" \
                ""$rerun_url""
        )""; then
            echo ""Re-launched the build for $josm_revision""
        else
            echo >&2 -n ""Could not re-launch the build for $josm_revision in $github_repo. Message: ""
            # Re-fetching with curl since --fail earlier doesn't let us capture output :/
            curl --silent -X POST \
                --header 'Accept: application/vnd.github.v3+json' \
                --header ""Authorization: token $github_oauth_token"" \
                ""$rerun_url"" | jq -r .message 1>&2
            exit 1
        fi
    fi
else
    echo >&2 ""Could not get runs for git-svn-id $1 in $github_repo. Did you maybe push on top of it in git  ? Have a look at https://api.github.com/repos/$github_repo/actions/runs""
    exit 1
fi
}}}"	enhancement	closed	normal	21.02	Installer MacOS		fixed	macos	Don-vip
