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

Version and changelog update on pull requests fails #80

Merged
merged 49 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
053d576
#78 Simply echoing toJSON of github context to find the "development"…
Ismoh Sep 25, 2022
22cf37c
#78 There is no build-in GitHub API endpoint or a context variable, w…
Ismoh Sep 25, 2022
2cfe7e0
#78 Adding comment when there is no linked issue.
Ismoh Sep 25, 2022
149cb15
#78 Fixed workflow: Repo needs to be checked out!
Ismoh Sep 25, 2022
3a21fc5
Update version-and-changelog-update.yml
Ismoh Sep 25, 2022
e2f45b6
#78 Trying to polish stuff, by using gh cli and api endpoints.
Ismoh Sep 26, 2022
2a766b1
#78 Moved gh cli command to the correct workflow step.
Ismoh Sep 26, 2022
d7c31de
#78 Changed command and quoting.
Ismoh Sep 26, 2022
94eb2e4
#78 Added GitHub token to be allowed to execute gh cli commands.
Ismoh Sep 26, 2022
850aa8b
#78 Added gh cli to get all comments regarding versioning and removin…
Ismoh Sep 26, 2022
cd38add
#78 Fixed wrong jq command.
Ismoh Sep 26, 2022
0092239
#78 Fixed missing quotes on jq command. Changed gource.io only runnin…
Ismoh Sep 26, 2022
7b0fc3d
#78 Fixed broken jq command.
Ismoh Sep 26, 2022
0782551
#78 Fixed broken workflow
Ismoh Sep 26, 2022
863d9e6
#78 Fixed GitHub API url and changed wording slightly.
Ismoh Sep 26, 2022
4592514
#78 Fixed quoting again.
Ismoh Sep 26, 2022
4e0365e
#78 Changed escaped body to non-escaped.
Ismoh Sep 26, 2022
3bf9cd9
#78 Fixed new line. Added comment for changelog.
Ismoh Sep 26, 2022
30b846c
#78 Fixed removing old comments and typos. Added removing changelog c…
Ismoh Sep 26, 2022
df9d42e
#78 Missed GitHub token.
Ismoh Sep 26, 2022
d518371
#78 Eeeh, new line in markdown with gh string: Fun fun fun !
Ismoh Sep 26, 2022
ba34851
#78 Eeeh, new line in markdown with gh string: Fun fun fun ! [space][…
Ismoh Sep 26, 2022
27154da
#78 Eeeh, new line in markdown with gh string: Fun fun fun ! \ ?
Ismoh Sep 26, 2022
098a6e1
#78 Eeeh, new line in markdown with gh string: Fun fun fun ! <br /> ?
Ismoh Sep 26, 2022
fb74891
#78 Playing around with escaping $CHANGELOG.
Ismoh Sep 27, 2022
d378a5c
#78 Fixed non-created changelog.
Ismoh Sep 27, 2022
1d51e69
#78 Fixed wrong output usage.
Ismoh Sep 27, 2022
c0108a1
#78 Getting rid of 'Unreleased' for this specific pull request. Next …
Ismoh Sep 27, 2022
b1d3001
#78 Fixed typo on env usage. Fixed deletion of previous comments.
Ismoh Sep 27, 2022
5faa864
#78 Where is the env gone?
Ismoh Sep 27, 2022
3810758
#78 Adding global environment variable to have access on it between j…
Ismoh Sep 27, 2022
7aac465
#78 Why is this environment variable not set?
Ismoh Sep 27, 2022
fde18f5
#78 Why is this environment variable still not set?
Ismoh Sep 27, 2022
2359c53
#78 Why is this environment variable still not set?
Ismoh Sep 27, 2022
3bdc97c
#78 Why is this environment variable still not set?
Ismoh Sep 27, 2022
5d1ee8d
#78 Global environments aren't working. Using GitHubs output now.
Ismoh Sep 27, 2022
9dbcc84
#78 Fixed outputs.
Ismoh Sep 27, 2022
56e797a
#78 Fixed naming.
Ismoh Sep 27, 2022
872fafd
#78 Added deletion of not linked issue.
Ismoh Sep 27, 2022
54929b4
#78 Where is the $ coming from?
Ismoh Sep 27, 2022
809ca3a
#78 Fixed typo, where unnecessary $ was added.
Ismoh Sep 27, 2022
5bbdf99
#78 Fixed usage of env. Misled by typo.
Ismoh Sep 27, 2022
b37a76e
#78 Getting headache from syntax differences.
Ismoh Sep 27, 2022
3cb763f
#78 Does env adds the $?
Ismoh Sep 27, 2022
7ee3633
#78 Last try to get this annoying $ removed!
Ismoh Sep 27, 2022
c8e7d86
#78 Fixed typo! Finally, found the unnecessary $!
Ismoh Sep 27, 2022
12cd6cd
#78 Clean up!
Ismoh Sep 27, 2022
9325be5
#78 Making it pretty!
Ismoh Sep 27, 2022
20f1b37
#78 Polishing!
Ismoh Sep 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/gource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Gource
on:
push:
branches:
- '**'
- 'develop'

jobs:
action:
Expand Down
147 changes: 127 additions & 20 deletions .github/workflows/version-and-changelog-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,62 @@ jobs:
name: Copy labels from issue to pull request
runs-on: ubuntu-latest
outputs:
labelNames: $${{ steps.add_labels.outputs.labelNames }}
labelNames: ${{ steps.add_labels.outputs.labelNames }}
steps:
- uses: actions/checkout@v3

- name: Is there a issue linked in "development"?
id: validator
uses: HarshCasper/[email protected]
with:
prbody: ${{ github.event.pull_request.body }}
prurl: ${{ github.event.pull_request.url }}

- name: "'Development' set?"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PRNUM: ${{ github.event.pull_request.number }}
run: |
commentListResponse=`gh api -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("Your pull request is not linked to any issue")) | .id')
echo "commentIds="$commentIds

for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done

if [ ${{ steps.validator.outputs.valid }} == 0 ]
then
body=":warning: :exclamation: Your pull request is not linked to any issue, please make the corresponding changes in the very first comments body by adding 'Fixes #issue-number' or 'Resolves #issue-number'. If your pull request isn't linked to any issue, ignore this comment!"
statusCode=`gh api --method POST -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments -f body="$body"`
echo "statusCode="$statusCode

if [[ $statusCode == "" ]]
then
echo "Unable to add comment to pull request!"
exit 1
fi
fi

- name: Find linked issues
if: ${{ steps.validator.outputs.valid == 1 }}
id: links
uses: hossainemruz/linked-issues@main
with:
pr_url: ${{github.event.pull_request.html_url}}
format: IssueNumber

- name: Add labels of associated/linked issue to the pull request
if: ${{ steps.validator.outputs.valid == 1 }}
id: add_labels
run: |
for issueNumber in ${{ steps.links.outputs.issues }}
Expand Down Expand Up @@ -49,7 +95,7 @@ jobs:
exit 1
fi

echo "::set-output name=labelNames::${labelNames}"
echo "::set-output name=labelNames::$labelNames"

update-version:
needs: find-linked-issues-and-copy-labels-to-pull-request
Expand All @@ -58,6 +104,8 @@ jobs:
VERSION_FILE_NAME: 'mods/noita-mp/.version'
VERSION_FRAGMENT: 'will be fetched by file'
name: Increase version and create a tag, when merged
outputs:
futureRelease: ${{ steps.extend_version.outputs.futureRelease }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -77,27 +125,44 @@ jobs:
next-version-put-build-metadata: true

- name: Extend version with custom build numbers
id: extend_version
run: |
echo "NEXT_VERSION=v$NEXT_VERSION+$(git log --oneline | wc -l)" >> $GITHUB_ENV
nextVersion="v$NEXT_VERSION+$(git log --oneline | wc -l)"
echo "nextVersion="$nextVersion
echo "NEXT_VERSION=${nextVersion}" >> $GITHUB_ENV
echo "::set-output name=futureRelease::$nextVersion"

- name: Add comment to pull request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
body="{\"body\":\"When this pull request was merged\\\:\r\n- Version will be automatically increase to **$NEXT_VERSION** in **${{ github.base_ref }}**\r\n- Tag **$NEXT_VERSION** will be created to the specific commit.\"}"
commentListResponse=`gh api -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("will be automatically increase to")) | .id')
echo "commentIds="$commentIds

curlResponse=`curl --write-out '%{http_code}' --output /dev/null --request POST \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: token ${{ github.token }}' \
--url 'https://api.github.com/repos/${{github.repository}}/issues/${{github.event.number}}/comments' \
--data-raw "$body"`
for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done

if [[ $curlResponse == *"201"* ]]
body="When this pull request was merged: <br /> - Current Version **v$CURRENT_VERSION** will be automatically increase to **$NEXT_VERSION** in **${{ github.base_ref }}** <br /> - Tag **$NEXT_VERSION** will be created to the specific commit."
statusCode=`gh api --method POST -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments -f body="$body"`
echo "statusCode="$statusCode

if [[ $statusCode == "" ]]
then
echo "SUCCESS"
else
echo "FAILURE"
echo "Unable to add comment to pull request!"
exit 1
fi

- name: Commit and push version changes and tag it, when merged
env:
MERGED: ${{ github.event.pull_request.merged }}
Expand All @@ -121,29 +186,72 @@ jobs:
update-changelog:
needs: update-version
env:
VERSION_FILE_NAME: 'mods/noita-mp/.version'
name: Update CHANGELOG.md, when merged
FUTURE_RELEASE: ${{ needs.update-version.outputs.futureRelease }}
name: Update CHANGELOG.md
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Generate CHANGELOG.md, when merged
if: ${{ github.event.pull_request.merged }}
- name: Check environment
run: |
echo "needs.update-version.env.next_version="${{ needs.update-version.env.next_version }}
echo "needs.update-version.env.NEXT_VERSION="${{ needs.update-version.env.NEXT_VERSION }}
echo "NEXT_VERSION="$NEXT_VERSION
echo "env.NEXT_VERSION="${{ env.NEXT_VERSION }}
echo "env.next_version=""${{ env.next_version }}"
echo "FUTURE_RELEASE="$FUTURE_RELEASE
echo "env.FUTURE_RELEASE="${{ env.FUTURE_RELEASE }}

- name: Generate CHANGELOG.md
id: generate_changelog
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
dateFormat: "%d.%m.%Y"
output: "CHANGELOG.md"
issueLineLabels: "ALL"
breakingLabels: "backwards-incompatible,breaking,rework,refactor"
futureRelease: ${{ env.FUTURE_RELEASE }}

- name: Commit and push CHANGELOG.md, when merged
env:
CHANGELOG: ${{ needs.update-changelog.outputs.changelog }}
CHANGELOG: ${{ steps.generate_changelog.outputs.changelog }}
MERGED: ${{ github.event.pull_request.merged }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
commentListResponse=`gh api -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments`
echo "commentListResponse="$commentListResponse
# https://jqplay.org/s/WsuVZ8f-YiB
commentIds=$(echo $commentListResponse | jq '.[] | select(.body | contains("# Changelog")) | .id')
echo "commentIds="$commentIds

for commentId in $commentIds
do
echo "commentId="$commentId
statusCode=`gh api --method DELETE -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/comments/$commentId`
echo "statusCode="$statusCode
if [[ $statusCode != "" ]]
then
echo "Unable to delete comment with id "$commentId
fi
done

echo ""
echo "CHANGELOG="$CHANGELOG
echo ""

printf -v escapedChangelog "%q\n" $CHANGELOG
echo "escapedChangelog="$escapedChangelog

statusCode=`gh api --method POST -H 'Accept: application/vnd.github+json' /repos/${{github.repository}}/issues/${{github.event.number}}/comments -f body="$CHANGELOG"`
echo "statusCode="$statusCode
if [[ $statusCode == "" ]]
then
echo "Unable to add comment to pull request!"
fi

if [ $MERGED == true ]
then
git fetch
Expand All @@ -157,4 +265,3 @@ jobs:
else
echo "Pull request is not merged yet, therefore CHANGELOG.md will not be updated."
fi