Skip to content

Commit 5ce9e7f

Browse files
authored
Merge branch 'master' into feat/stream-sync-edge-cases
2 parents acb0361 + 2016ecb commit 5ce9e7f

File tree

1 file changed

+38
-107
lines changed

1 file changed

+38
-107
lines changed

.github/workflows/release-sync.yml

Lines changed: 38 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ jobs:
1313
GH_TOKEN: ${{ secrets.RELEASE_TOKEN }}
1414
ORG_NAME: HathorNetwork
1515
PROJECT_NUMBER: 15
16+
COLUMN_FIELD: "Status"
1617
COLUMN_NAME: "In Progress (Done)"
18+
FROM_BRANCH: "release"
19+
TO_BRANCH: "master"
1720

1821
steps:
1922
- name: Checkout
@@ -22,135 +25,63 @@ jobs:
2225
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29
2326

2427
- name: Create Pull Request
28+
env:
29+
TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
2530
id: create_pull
2631
run: |
32+
echo "Finding author of release $TAG"
33+
AUTHOR=$(gh release view $TAG --json author -q '.author.login')
34+
echo "release author: $AUTHOR"
35+
36+
# This just checks that the user exists, if the release could not be found the AUTHOR
37+
# would be "release not found" which is a non-existant user.
38+
[$(gh api -X GET search/users -f q=$AUTHOR) == "0"] && echo "Could not find author" && exit 1;
39+
40+
echo "Creating chore/sync-release-$TAG from release branch"
41+
git fetch origin $TO_BRANCH:$TO_BRANCH $FROM_BRANCH:$FROM_BRANCH
42+
git checkout $FROM_BRANCH
43+
git checkout -b chore/sync-release-$TAG
44+
git push -u origin chore/sync-release-$TAG
45+
2746
# The assignee will be the user that manually published the release
2847
PR_URL=$(gh pr create \
2948
--title "chore: [${{ github.ref_name }}] Merge release into master" \
3049
--body "Automated PR to merge `release` branch into `master` based on release event." \
31-
--base "master" \
32-
--head "release" \
33-
--assignee "@me")
34-
35-
# Obtaining the PR number from its URL
36-
PR_NUMBER=$(echo $PR_URL | grep -oP '/pull/\K\d+')
50+
--base "$TO_BRANCH" \
51+
--head "chore/sync-release-$TAG" \
52+
--assignee "$AUTHOR")
3753
3854
# Store values in step output
3955
echo "PR_URL=$PR_URL" >> "$GITHUB_OUTPUT"
40-
echo "PR_NUMBER=$PR_NUMBER" >> "$GITHUB_OUTPUT"
41-
42-
- name: Associate PR with project
43-
env:
44-
PR_URL: ${{ steps.create_pull.outputs.PR_URL }}
45-
run: |
46-
gh project item-add $PROJECT_NUMBER \
47-
--owner $ORG_NAME \
48-
--url "$PR_URL" \
4956
5057
- name: Fetch project and column data
5158
id: proj_columns
52-
# There is no direct command to move a card inside a project. Here we start gathering id data about the project
53-
# to do this operation through the API
5459
run: |
55-
QUERY="
56-
query {
57-
organization(login: \"$ORG_NAME\") {
58-
projectV2(number: $PROJECT_NUMBER) {
59-
id
60-
field(name: \"Status\") {
61-
__typename
62-
...on ProjectV2SingleSelectField {
63-
id
64-
options {
65-
id
66-
name
67-
}
68-
}
69-
}
70-
}
71-
}
72-
}
73-
"
74-
PROJ_RESPONSE=$(gh api graphql -f query="$QUERY")
60+
FIELD_QUERY=".fields[] | select(.name==\"$COLUMN_FIELD\") | .id"
61+
FIELD_ID=$(gh project field-list $PROJECT_NUMBER --owner $ORG_NAME --format json -q "$FIELD_QUERY")
7562
76-
# Parse json response and fetch necessary data identifiers from it
77-
PROJ_DATA=$(echo "$PROJ_RESPONSE" | jq -r --arg column_name "$COLUMN_NAME" '
78-
.data.organization.projectV2.id as $projectId |
79-
.data.organization.projectV2.field.id as $fieldId |
80-
.data.organization.projectV2.field.options[] |
81-
select(.name == $column_name) |
82-
{
83-
projectId: $projectId,
84-
fieldId: $fieldId,
85-
optionId: .id
86-
}')
87-
PROJECT_ID=$(echo "$PROJ_DATA" | jq -r '.projectId')
88-
FIELD_ID=$(echo "$PROJ_DATA" | jq -r '.fieldId')
89-
OPTION_ID=$(echo "$PROJ_DATA" | jq -r '.optionId')
63+
OPTION_QUERY=".fields[] | select(.name==\"$COLUMN_FIELD\") | .options[] | select(.name==\"$COLUMN_NAME\") | .id"
64+
OPTION_ID=$(gh project field-list $PROJECT_NUMBER --owner $ORG_NAME --format json -q "$OPTION_QUERY")
65+
66+
PROJECT_QUERY=".projects[] | select(.number==$PROJECT_NUMBER) | .id"
67+
PROJECT_ID=$(gh project list --owner $ORG_NAME --format json -q "$PROJECT_QUERY")
9068
9169
# Store values in step output
9270
echo "PROJECT_ID=$PROJECT_ID" >> "$GITHUB_OUTPUT"
9371
echo "FIELD_ID=$FIELD_ID" >> "$GITHUB_OUTPUT"
9472
echo "OPTION_ID=$OPTION_ID" >> "$GITHUB_OUTPUT"
9573
96-
- name: Fetch PR card Id
97-
id: proj_cardId
98-
env:
99-
PR_NUMBER: ${{ steps.create_pull.outputs.PR_NUMBER }}
100-
run: |
101-
# The github repository contains the owner organization too: we need to get only the last part of it
102-
REPO_NAME=$(basename ${{ github.repository }})
103-
104-
# Executing graphql query to fetch the Id of the card that links the PR to the Project
105-
QUERY="
106-
query {
107-
repository(owner: \"$ORG_NAME\", name: \"$REPO_NAME\") {
108-
pullRequest(number: $PR_NUMBER) {
109-
id
110-
projectItems(first: 100) {
111-
... on ProjectV2ItemConnection {
112-
nodes {
113-
... on ProjectV2Item {
114-
id
115-
}
116-
}
117-
}
118-
}
119-
}
120-
}
121-
}"
122-
PROJ_RESPONSE=$(gh api graphql -f query="$QUERY")
123-
124-
# Fetching the id of the project card related to this PR
125-
CARD_ID=$(echo "$PROJ_RESPONSE" | jq -r '.data.repository.pullRequest.projectItems.nodes[0].id')
126-
127-
# Store value in step output
128-
echo "CARD_ID=$CARD_ID" >> "$GITHUB_OUTPUT"
129-
130-
- name: Move card to correct column
131-
id: mutateCard
74+
- name: Associate PR with project
13275
env:
76+
PR_URL: ${{ steps.create_pull.outputs.PR_URL }}
13377
PROJECT_ID: ${{ steps.proj_columns.outputs.PROJECT_ID }}
13478
FIELD_ID: ${{ steps.proj_columns.outputs.FIELD_ID }}
13579
OPTION_ID: ${{ steps.proj_columns.outputs.OPTION_ID }}
136-
CARD_ID: ${{ steps.proj_cardId.outputs.CARD_ID }}
13780
run: |
138-
QUERY="
139-
mutation {
140-
updateProjectV2ItemFieldValue(
141-
input: {
142-
projectId: \"$PROJECT_ID\",
143-
itemId: \"$CARD_ID\",
144-
fieldId: \"$FIELD_ID\",
145-
value: {
146-
singleSelectOptionId: \"$OPTION_ID\"
147-
}
148-
}
149-
) {
150-
projectV2Item {
151-
id
152-
}
153-
}
154-
}
155-
"
156-
PROJ_RESPONSE=$(gh api graphql -f query="$QUERY")
81+
ITEM_ID=$(gh project item-add $PROJECT_NUMBER \
82+
--owner $ORG_NAME \
83+
--url "$PR_URL" \
84+
--format json \
85+
-q '.id' )
86+
87+
gh project item-edit --project-id $PROJECT_ID --id $ITEM_ID --field-id $FIELD_ID --single-select-option-id $OPTION_ID

0 commit comments

Comments
 (0)