-
Notifications
You must be signed in to change notification settings - Fork 1
87 lines (84 loc) · 4.29 KB
/
create-draft-release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Create GitHub draft release
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
create_draft_release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: '0'
fetch-tags: 'true'
- name: Set up git identity
run: |
git config --local user.email "[email protected]"
git config --local user.name "taylorbot"
- name: Create or update draft release tags
run: |
git fetch --tags
for aws_release_dir in capa/*; do
if [[ -f $aws_release_dir ]]; then
echo "Skipping file $aws_release_dir"
continue
fi
aws_release_version="$(basename $aws_release_dir)"
echo "Found AWS release $aws_release_version"
draft_tag_name="draft/aws/$aws_release_version"
if [ $(git tag -l "$draft_tag_name") ]; then
echo "Found existing tag $draft_tag_name, will force-overwrite it"
# Delete origin tag
git push --delete origin "$draft_tag_name"
# Create new tag locally
git tag -fa "$draft_tag_name" -m "AWS draft release $aws_release_version"
git push -f origin "$draft_tag_name"
else
echo "Tag $draft_tag_name not found"
published_tag_name="aws/$aws_release_version"
published_release=$(gh release --repo giantswarm/releases view "$published_tag_name" --json "id,name,tagName,assets,isDraft,isPrerelease,url" 2>&1 || true)
if [ "$published_release" = "release not found" ]; then
echo "Didn't find a release for neither published tag $published_tag_name nor for tag $draft_tag_name. Will create a new draft tag."
git tag -a "$draft_tag_name" -m "AWS (CAPA) draft release $aws_release_version"
git push -f origin "$draft_tag_name"
else
echo "Found a published release with tag $published_tag_name. Skipping draft tag creation."
fi
fi
done
- name: Create or update draft releases
env:
GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}"
BRANCH: ${{ github.head_ref }}
run: |
for aws_release_dir in capa/*; do
if [[ -f $aws_release_dir ]]; then
echo "Skipping file $aws_release_dir"
continue
fi
aws_release_version="$(basename $aws_release_dir)"
draft_tag_name="draft/aws/$aws_release_version"
draft_release=$(gh release --repo giantswarm/releases view "$draft_tag_name" --json "id,name,tagName,assets,isDraft,isPrerelease,url" 2>&1 || true)
current_commit="$(git rev-parse HEAD)"
release_title="Draft workload cluster release $aws_release_version for AWS (CAPA)"
pr_number="$(gh pr view "$BRANCH" --json "number" --jq ".number")"
release_note="DO NOT USE FOR PRODUCTION PURPOSES. See PR #${pr_number} for more details. This draft release has been created automatically by GitHub action. It will be deleted when the PR is merged."
if [ "$draft_release" = "release not found" ]; then
published_tag_name="aws/$aws_release_version"
published_release=$(gh release --repo giantswarm/releases view "$published_tag_name" --json "id,name,tagName,assets,isDraft,isPrerelease,url" 2>&1 || true)
if [ "$published_release" = "release not found" ]; then
echo "Didn't find a release for neither published tag $published_tag_name nor for tag $draft_tag_name. Will create a new draft release."
gh release create --repo giantswarm/releases --draft --target "$current_commit" --title "$release_title" --notes "$release_note" "$draft_tag_name" "$aws_release_dir/release.yaml"
else
echo "Found a published release with tag $published_tag_name. Skipping draft release creation."
fi
else
echo "Found existing draft release $draft_tag_name, will update it."
gh release edit --repo giantswarm/releases --draft --target "$current_commit" --title "$release_title" --notes "$release_note" "$draft_tag_name"
gh release upload --repo giantswarm/releases --clobber "$draft_tag_name" "$aws_release_dir/release.yaml"
fi
done