Skip to content

Automate release steps with the Buildkite release triggers #325

@wilzbach

Description

@wilzbach

Now that we have an easy to edit buildkite pipeline, we could add a few more automations to an automated release trigger (i.e. https://buildkite.com/docs/pipelines/trigger-step).

Ideas:

Martin's release script is here: https://gist.github.com/MartinNowak/a471fe7ddbfeef205cdf04c93a94c6d0

So in short automating bits of it.

Update the wiki

As an example, here's how to update the wiki with a USERNAME + USERPASS.

Details ```bash set -eux -o pipefail

USERNAME="username"
USERPASS="password"
PAGE="Template:Latest_DMD_Version_Raw"
WIKIAPI="https://wiki.dlang.org/api.php"
cookie_jar="/opt/dlang/wikicj"
#Will store file in wikifile

echo "UTF8 check: ☠"
#################login
echo "Logging into $WIKIAPI as $USERNAME..."

text=$(curl --fail --retry 3 http://downloads.dlang.org/releases/LATEST)

###############
#Login part 1
#printf "%s" "Logging in (1/2)..."
echo "Get login token..."
CR=$(curl -S
--location
--retry 2
--retry-delay 5
--cookie $cookie_jar
--cookie-jar $cookie_jar
--user-agent "Curl Shell Script"
--keepalive-time 60
--header "Accept-Language: en-us"
--header "Connection: keep-alive"
--compressed
--request "GET" "${WIKIAPI}?action=query&meta=tokens&type=login&format=json")

echo "$CR" | jq .

rm -f login.json
echo "$CR" > login.json
TOKEN=$(jq --raw-output '.query.tokens.logintoken' login.json)
TOKEN="${TOKEN//"/}" #replace double quote by nothing

#Remove carriage return!
printf "%s" "$TOKEN" > token.txt
TOKEN=$(cat token.txt | sed 's/\r$//')

if [ "$TOKEN" == "null" ]; then
echo "Getting a login token failed."
exit
else
echo "Login token is $TOKEN"
echo "-----"
fi

###############
#Login part 2
echo "Logging in..."
CR=$(curl -S
--location
--cookie $cookie_jar
--cookie-jar $cookie_jar
--user-agent "Curl Shell Script"
--keepalive-time 60
--header "Accept-Language: en-us"
--header "Connection: keep-alive"
--compressed
--data-urlencode "username=${USERNAME}"
--data-urlencode "password=${USERPASS}"
--data-urlencode "rememberMe=1"
--data-urlencode "logintoken=${TOKEN}"
--data-urlencode "loginreturnurl=http://en.wikipedia.org"
--request "POST" "${WIKIAPI}?action=clientlogin&format=json")

echo "$CR" | jq .

STATUS=$(echo $CR | jq '.clientlogin.status')
if [[ $STATUS == "PASS" ]]; then
echo "Successfully logged in as $USERNAME, STATUS is $STATUS."
echo "-----"
else
echo "Unable to login, is logintoken ${TOKEN} correct?"
exit
fi

###############
#Get edit token
echo "Fetching edit token..."
CR=$(curl -S
--location
--cookie $cookie_jar
--cookie-jar $cookie_jar
--user-agent "Curl Shell Script"
--keepalive-time 60
--header "Accept-Language: en-us"
--header "Connection: keep-alive"
--compressed
--request "POST" "${WIKIAPI}?action=query&meta=tokens&format=json")

echo "$CR" | jq .
echo "$CR" > edittoken.json
EDITTOKEN=$(jq --raw-output '.query.tokens.csrftoken' edittoken.json)
rm edittoken.json

EDITTOKEN="${EDITTOKEN//"/}" #replace double quote by nothing

#Remove carriage return!
printf "%s" "$EDITTOKEN" > edittoken.txt
EDITTOKEN=$(cat edittoken.txt | sed 's/\r$//')

if [[ $EDITTOKEN == "+\" ]]; then
echo "Edit token is: $EDITTOKEN"
else
echo "Edit token not set."
exit
fi

###############
#Make a test edit
CR=$(curl -S
--location
--cookie $cookie_jar
--cookie-jar $cookie_jar
--user-agent "Curl Shell Script"
--keepalive-time 60
--header "Accept-Language: en-us"
--header "Connection: keep-alive"
--compressed
--data-urlencode "title=${PAGE}"
--data-urlencode "text=${text}"
--data-urlencode "summary=auto bump"
--data-urlencode "token=${EDITTOKEN}"
--request "POST" "${WIKIAPI}?action=edit&format=json")

echo "$CR" | jq .

</details>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions