Skip to content

Commit

Permalink
feat(github-actions): ensure single tag for automated commits and upd…
Browse files Browse the repository at this point in the history
…ate PR creation action

Added a GitHub Action to check for a single tag on the last commit in a PR to enforce workflow consistency and prevent tagging errors. Updated the `create-pull-request` action to the latest version, added explicit author and committer fields, and specified a reviewer to streamline the automated model update process. Removed the pre-merge checklist from the pull request body to simplify and focus on automated tasks.
  • Loading branch information
Sett17 committed Nov 21, 2023
1 parent 6b5cf7b commit e3876a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/tag_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Check Tag on Automated Commit
on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
check-tag:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Get PR Author
id: pr_author
run: |
pr_author_email=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" \
| jq -r .user.email)
echo "author_email=$pr_author_email" >> $GITHUB_ENV
- name: Check for Single Tag on Last Commit
if: env.author_email == 'noreply@github.com'
run: |
last_commit=$(git rev-parse HEAD)
tags=$(git tag --contains $last_commit)
tag_count=$(echo "$tags" | wc -l | xargs)
if [ "$tag_count" -ne 1 ]; then
echo "The last commit does not have exactly one tag."
exit 1
fi
echo "Commit $last_commit has exactly one tag: $tags"
16 changes: 8 additions & 8 deletions .github/workflows/update_models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
generate-and-create-pr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'

Expand All @@ -28,17 +28,17 @@ jobs:
- name: Extract Version from Cargo.toml
run: |
version=$(python -c "import toml; print(toml.load('Cargo.toml')['package']['version'])")
echo "Extracted version: $version"
echo "VERSION=$version" >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v5
with:
title: "Automated Model Update"
commit-message: "Automated update of model definitions"
branch: "update-models-${{ steps.extract_version.outputs.version }}"
branch: "update-models-${{ env.VERSION }}"
author: "GitHub Workflow <noreply@github.com>"
committer: "GitHub Workflow <noreply@github.com>"
reviewers: "Sett17"
body: |
This is an automated pull request to update the model definitions.
**Before merging:**
- [ ] Ensure to create a new tag with the version ${{ steps.extract_version.outputs.version }} after merging.
signoff: true

0 comments on commit e3876a3

Please sign in to comment.