Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate release steps with the Buildkite release triggers #325

Open
wilzbach opened this issue Oct 22, 2018 · 1 comment
Open

Automate release steps with the Buildkite release triggers #325

wilzbach opened this issue Oct 22, 2018 · 1 comment

Comments

@wilzbach
Copy link
Member

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.

```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>
@MartinNowak
Copy link
Member

Well the script is automation already and it's unclear whether moving it into a public CI pipeline will work reliably.
It seems more worthwhile to focus on fixing other stuff or improve our CI mess rather than to replace a working system (that's only used monthly) with a new one. Your wiki update script gives a hint at the lingering fragility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants