|
| 1 | +GITHUB_RELEASE_SPEC_FILE="/tmp/vm-github-release" |
| 2 | +GITHUB_DEBUG_FILE="/tmp/vm-github-debug" |
| 3 | + |
| 4 | +github-token-check: |
| 5 | +ifndef GITHUB_TOKEN |
| 6 | + $(error missing GITHUB_TOKEN env var. It must contain github token for VictoriaMetrics project obtained from https://github.com/settings/tokens) |
| 7 | +endif |
| 8 | + |
| 9 | +github-tag-check: |
| 10 | +ifndef TAG |
| 11 | + $(error missing TAG env var. It must contain github release tag to create) |
| 12 | +endif |
| 13 | + |
| 14 | +github-create-release: github-token-check github-tag-check |
| 15 | + @result=$$(curl -o $(GITHUB_RELEASE_SPEC_FILE) -s -w "%{http_code}" \ |
| 16 | + -X POST \ |
| 17 | + -H "Accept: application/vnd.github+json" \ |
| 18 | + -H "Authorization: token $(GITHUB_TOKEN)" \ |
| 19 | + https://api.github.com/repos/VictoriaMetrics/VictoriaMetrics/releases \ |
| 20 | + -d '{"tag_name":"$(TAG)","name":"$(TAG)","body":"TODO: put here the changelog for $(TAG) release from docs/CHANGELOG.md","draft":true,"prerelease":false,"generate_release_notes":false}'); \ |
| 21 | + if [ $${result} = 201 ]; then \ |
| 22 | + release_id=$$(cat $(GITHUB_RELEASE_SPEC_FILE) | grep '"id"' -m 1 | sed -E 's/.* ([[:digit:]]+)\,/\1/'); \ |
| 23 | + printf "Created release $(TAG) with id=$${release_id}\n"; \ |
| 24 | + else \ |
| 25 | + printf "Failed to create release $(TAG)\n"; \ |
| 26 | + cat $(GITHUB_RELEASE_SPEC_FILE); \ |
| 27 | + exit 1; \ |
| 28 | + fi |
| 29 | + |
| 30 | +github-upload-assets: |
| 31 | + @release_id=$$(cat $(GITHUB_RELEASE_SPEC_FILE) | grep '"id"' -m 1 | sed -E 's/.* ([[:digit:]]+)\,/\1/'); \ |
| 32 | + $(foreach file, $(wildcard bin/*.zip), FILE=$(file) RELEASE_ID=$${release_id} CONTENT_TYPE="application/zip" $(MAKE) github-upload-asset || exit 1;) \ |
| 33 | + $(foreach file, $(wildcard bin/*.tar.gz), FILE=$(file) RELEASE_ID=$${release_id} CONTENT_TYPE="application/x-gzip" $(MAKE) github-upload-asset || exit 1;) \ |
| 34 | + $(foreach file, $(wildcard bin/*_checksums.txt), FILE=$(file) RELEASE_ID=$${release_id} CONTENT_TYPE="text/plain" $(MAKE) github-upload-asset || exit 1;) |
| 35 | + |
| 36 | +github-upload-asset: github-token-check |
| 37 | +ifndef FILE |
| 38 | + $(error missing FILE env var. It must contain path to file to upload to github release) |
| 39 | +endif |
| 40 | + @printf "Uploading $(FILE)\n" |
| 41 | + @result=$$(curl -o $(GITHUB_DEBUG_FILE) -w "%{http_code}" \ |
| 42 | + -X POST \ |
| 43 | + -H "Accept: application/vnd.github+json" \ |
| 44 | + -H "Authorization: token $(GITHUB_TOKEN)" \ |
| 45 | + -H "Content-Type: $(CONTENT_TYPE)" \ |
| 46 | + --data-binary "@$(FILE)" \ |
| 47 | + https://uploads.github.com/repos/VictoriaMetrics/VictoriaMetrics/releases/$(RELEASE_ID)/assets?name=$(notdir $(FILE))); \ |
| 48 | + if [ $${result} = 201 ]; then \ |
| 49 | + printf "Upload OK: $${result}\n"; \ |
| 50 | + elif [ $${result} = 422 ]; then \ |
| 51 | + printf "Asset already uploaded, you need to delete it from UI if you want to re-upload it\n"; \ |
| 52 | + else \ |
| 53 | + printf "Upload failed: $${result}\n"; \ |
| 54 | + cat $(GITHUB_DEBUG_FILE); \ |
| 55 | + exit 1; \ |
| 56 | + fi |
| 57 | + |
| 58 | +github-delete-release: github-token-check |
| 59 | + @release_id=$$(cat $(GITHUB_RELEASE_SPEC_FILE) | grep '"id"' -m 1 | sed -E 's/.* ([[:digit:]]+)\,/\1/'); \ |
| 60 | + result=$$(curl -o $(GITHUB_DEBUG_FILE) -s -w "%{http_code}" \ |
| 61 | + -X DELETE \ |
| 62 | + -H "Accept: application/vnd.github+json" \ |
| 63 | + -H "Authorization: token $(GITHUB_TOKEN)" \ |
| 64 | + https://api.github.com/repos/VictoriaMetrics/VictoriaMetrics/releases/$${release_id}); \ |
| 65 | + if [ $${result} = 204 ]; then \ |
| 66 | + printf "Deleted release with id=$${release_id}\n"; \ |
| 67 | + else \ |
| 68 | + printf "Failed to delete release with id=$${release_id}\n"; \ |
| 69 | + cat $(GITHUB_DEBUG_FILE); \ |
| 70 | + exit 1; \ |
| 71 | + fi |
0 commit comments