Contributing and code of conduct and improve maintainers duties #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release Tagging | |
on: | |
pull_request: | |
types: [opened, reopened, synchronize, closed] | |
permissions: | |
contents: write # Allows pushing changes and creating tags | |
pull-requests: write # Allows adding comments to pull requests | |
issues: write | |
jobs: | |
tag-discussion: | |
if: github.event.action == 'synchronize' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Get the latest tag | |
id: get_tag | |
run: | | |
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
echo "::set-output name=latest_tag::$LATEST_TAG" | |
- name: Calculate new versions | |
id: calculate_versions | |
run: | | |
LATEST_TAG=${{ steps.get_tag.outputs.latest_tag }} | |
MAJOR=$(echo $LATEST_TAG | cut -d. -f1) | |
MINOR=$(echo $LATEST_TAG | cut -d. -f2) | |
PATCH=$(echo $LATEST_TAG | cut -d. -f3) | |
NEW_PATCH_VERSION="$MAJOR.$MINOR.$((PATCH + 1))" | |
NEW_MINOR_VERSION="$MAJOR.$((MINOR + 1)).0" | |
NEW_MAJOR_VERSION="$((MAJOR + 1)).0.0" | |
echo "::set-output name=patch_version::$NEW_PATCH_VERSION" | |
echo "::set-output name=minor_version::$NEW_MINOR_VERSION" | |
echo "::set-output name=major_version::$NEW_MAJOR_VERSION" | |
- name: Start Discussion for Tagging | |
uses: peter-evans/create-or-update-comment@v2 | |
id: comment | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
## Tagging Options | |
Should a new tag be published when this PR is merged? | |
- 👍 for **Patch** ${{ steps.calculate_versions.outputs.patch_version }} update | |
- 🎉 for **Minor** ${{ steps.calculate_versions.outputs.minor_version }} update | |
- 🚀 for **Major** ${{ steps.calculate_versions.outputs.major_version }} update | |
determine-tag: | |
if: github.event.action == 'closed' && github.event.pull_request.merged == true && github.ref == 'refs/heads/main' | |
needs: tag-discussion | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v3 | |
- name: Get the latest tag | |
id: get_tag | |
run: | | |
LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
echo "::set-output name=latest_tag::$LATEST_TAG" | |
- name: Determine the next version based on comments | |
id: determine_version | |
run: | | |
LATEST_TAG=${{ steps.get_tag.outputs.latest_tag }} | |
MAJOR=$(echo $LATEST_TAG | cut -d. -f1) | |
MINOR=$(echo $LATEST_TAG | cut -d. -f2) | |
PATCH=$(echo $LATEST_TAG | cut -d. -f3) | |
# Define allowed users | |
ALLOWED_USERS=$(cat MAINTAINERS.txt | tr '\n' ' ') | |
echo "Maintainers list: $ALLOWED_USERS" | |
# Fetch reactions and filter by allowed users | |
REACTION=$(gh api graphql -f query=' | |
query { | |
repository(owner:"${{ github.repository_owner }}", name:"${{ github.event.repository.name }}") { | |
pullRequest(number: ${{ github.event.pull_request.number }}) { | |
comments(last: 100) { | |
nodes { | |
body | |
id | |
reactions(last: 100) { | |
nodes { | |
content | |
user { | |
login | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}' | jq -r ' | |
.data.repository.pullRequest.comments.nodes[] | | |
select(.body | contains("## Tagging Options")) | | |
.reactions.nodes[] | | |
select(.user.login | inside(["'${ALLOWED_USERS[*]}'"])) | | |
.content' | |
) | |
# Determine the new tag version based on the allowed reactions | |
if [[ "$REACTION" == *"ROCKET"* ]]; then | |
NEW_TAG="$((MAJOR + 1)).0.0" | |
elif [[ "$REACTION" == *"TADA"* ]]; then | |
NEW_TAG="$MAJOR.$((MINOR + 1)).0" | |
else | |
NEW_TAG="$MAJOR.$MINOR.$((PATCH + 1))" | |
fi | |
echo "::set-output name=new_version::$NEW_TAG" | |
- name: Update deno.json Version | |
run: | | |
jq --arg new_version "${{ steps.determine_version.outputs.new_version }}" '.version = $new_version' deno.json > tmp.$$.json && mv tmp.$$.json deno.json | |
git config user.name "decobot" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git add deno.json | |
git commit -m "Update version to ${{ steps.determine_version.outputs.new_version }}" | |
git push origin main | |
- name: Create and Push Tag | |
run: | | |
git tag ${{ steps.determine_version.outputs.new_version }} | |
git push origin ${{ steps.determine_version.outputs.new_version }} |