1#!/usr/bin/env bash
2
3set -e
4set -u
5set -o pipefail
6
7REPOSITORY="MitMaro/git-interactive-rebase-tool"
8TARGET_RELEASE_ID=18843342
9
10cargo build --release --features nightly
11
12echo "Pushing release for $OS"
13
14if [[ "$OS" == "debian" ]]; then
15    cargo deb
16fi
17
18assets="$(curl -X GET \
19 -H "accept: application/vnd.github.dorian-preview+json"  \
20 -H "content-type: application/json" \
21 -H "authorization: token $GITHUB_ACCESS_TOKEN" \
22 "https://api.github.com/repos/$REPOSITORY/releases/$TARGET_RELEASE_ID/assets" | tr -d '\n')"
23
24assets="$(python -c "
25import json
26assets = json.loads('$assets')
27for asset in assets:
28    print asset['name'], asset['id']
29")"
30
31while read name id; do
32    assetid=
33    if [[ "$OS" == "debian" && "$name" == "git-interactive-rebase-tool_latest_amd64.deb" ]]; then
34        assetid="$id"
35    elif [[ "$OS" == "mac" && "$name" == "macos-interactive-rebase-tool" ]]; then
36        assetid="$id"
37    fi
38    if [[ -n "$assetid" ]]; then
39        curl -X DELETE \
40         -H "accept: application/vnd.github.dorian-preview+json"  \
41         -H "authorization: token $GITHUB_ACCESS_TOKEN" \
42         "https://api.github.com/repos/$REPOSITORY/releases/assets/$assetid"
43    fi
44done <<< "$assets"
45
46if [[ "$OS" == "debian" ]]; then
47    curl -X POST \
48     -H "accept: application/vnd.github.dorian-preview+json"  \
49     -H "content-type: application/vnd.debian.binary-package" \
50     -H "authorization: token $GITHUB_ACCESS_TOKEN" \
51     --data-binary @"$(echo target/debian/git-interactive-rebase-tool*.deb)" \
52     "https://uploads.github.com/repos/$REPOSITORY/releases/$TARGET_RELEASE_ID/assets?name=git-interactive-rebase-tool_latest_amd64.deb"
53elif [[ "$OS" == "mac" ]]; then
54    curl -X POST \
55     -H "accept: application/vnd.github.dorian-preview+json"  \
56     -H "content-type: application/x-mach-binary" \
57     -H "authorization: token $GITHUB_ACCESS_TOKEN" \
58     --data-binary @target/release/macos-interactive-rebase-tool \
59     "https://uploads.github.com/repos/$REPOSITORY/releases/$TARGET_RELEASE_ID/assets?name=macos-interactive-rebase-tool"
60fi
61
62master_ref="$(git rev-parse origin/master)"
63
64curl -X PATCH \
65 -H "accept: application/vnd.github.dorian-preview+json"  \
66 -H "content-type: application/json" \
67 -H "authorization: token $GITHUB_ACCESS_TOKEN" \
68 -d "{\"sha\": \"$master_ref\", \"force\": true}" \
69 "https://api.github.com/repos/$REPOSITORY/git/refs/tags/latest"
70