Skip to content

Commit

Permalink
Merge pull request #493 from ladesa-ro/dev/gabriel
Browse files Browse the repository at this point in the history
dev/gabriel
  • Loading branch information
guesant authored Jan 26, 2025
2 parents e043447 + 4d0c148 commit 0392701
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .changeset/empty-dragons-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: "CI: Generate Integrations"
name: "Autofix: Integrations and Static Code Quality"

on:
push:
branches:
- development
paths:
- .github/workflows/ci-generate-integrations.yml
- .github/workflows/automated-improvements.yml
- api-service/**/*
- package.json
- pnpm-lock.yaml
Expand All @@ -15,14 +15,20 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}

env:
PR_TARGET_BRANCH: development
BRANCH_GENERATED_INTEGRATIONS: automated-ci/generate-integrations
has_changes: false

INTEGRATIONS_PATH: integrations
GENERATED_COMMIT_MESSAGE: "chore(integrations/openapi-json): automated update"
observe_path: .

commit_author_name: "github-actions[bot]"
commit_author_email: "41898282+github-actions[bot]@users.noreply.github.com"
commit_message: "chore: autofix code"

commit_branch: github-actions-bot/autofix-development

pr_target_branch: development

jobs:
ci-generate-integrations:
job:
runs-on: ubuntu-latest

permissions:
Expand All @@ -39,48 +45,48 @@ jobs:
with:
install-node: "true"

- name: Generate integrations
- name: Generate Integrations
run: pnpm exec nx run-many -t generate --projects=tag:integrations;

- name: Format integrations
run: pnpm run -w format:fix integrations;
- name: Format Everything
run: pnpm run -w format:fix ${observe_path};

- name: Check if has changes
run: |
if git status --porcelain | grep -q -E "^\?\? ${INTEGRATIONS_PATH}|^ M ${INTEGRATIONS_PATH}"; then
if git status --porcelain | grep -q -E "^\?\? ${observe_path}|^ M ${observe_path}"; then
echo "has_changes=true" >> $GITHUB_ENV
else
echo "has_changes=false" >> $GITHUB_ENV
fi
- name: Set up Git
- name: Autofix - Set up Git
if: env.has_changes == 'true'
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "${commit_author_name}"
git config --global user.email "${commit_author_email}"
- name: Commit and push
- name: Autofix - Commit and Push
if: env.has_changes == 'true'
run: |
git add ${INTEGRATIONS_PATH};
git commit -m "${GENERATED_COMMIT_MESSAGE}";
git add -A ${observe_path};
git commit -m "${commit_message}";
if git show-ref --verify --quiet refs/heads/${BRANCH_GENERATED_INTEGRATIONS}; then
git branch -D ${BRANCH_GENERATED_INTEGRATIONS}
if git show-ref --verify --quiet refs/heads/${commit_branch}; then
git branch -D ${commit_branch}
fi
git checkout -b ${BRANCH_GENERATED_INTEGRATIONS}
git push origin ${BRANCH_GENERATED_INTEGRATIONS} --force
git checkout -b ${commit_branch}
git push origin ${commit_branch} --force
- name: Create or update pull request
if: env.has_changes == 'true'
run: |
# source: https://github.com/cli/cli/discussions/5792#discussioncomment-10410197
PR_URL="$(gh pr list -B "${PR_TARGET_BRANCH}" -H "${BRANCH_GENERATED_INTEGRATIONS}" --state open --json url --jq .[].url)"
PR_URL="$(gh pr list -B "${pr_target_branch}" -H "${commit_branch}" --state open --json url --jq .[].url)"
NOW=$(date +'%Y-%m-%dT%H:%M:%S')
PR_TITLE="${GENERATED_COMMIT_MESSAGE}"
PR_TITLE="${commit_message}"
PR_BODY="**Workflow**: ${{ github.workflow }}\n**Job**: ${{ github.job }}.\n**Run number**: ${{ github.run_number }}.\nUpdated at: ${NOW}."
PR_BODY_FILE="/tmp/pr-body.txt"
Expand All @@ -95,8 +101,8 @@ jobs:
;
else
gh pr create \
-B "${{ env.target-branch }}" \
-H "${{ env.generated-branch }}" \
-B "${{ env.pr_target_branch }}" \
-H "${{ env.commit_branch }}" \
--title "${PR_TITLE}" \
--body-file "${PR_BODY_FILE}" \
;
Expand All @@ -109,7 +115,7 @@ jobs:
if: env.has_changes == 'false'
run: |
# source: https://github.com/cli/cli/discussions/5792#discussioncomment-10410197
PR_URL="$(gh pr list -B "${PR_TARGET_BRANCH}" -H "${BRANCH_GENERATED_INTEGRATIONS}" --state open --json url --jq .[].url)"
PR_URL="$(gh pr list -B "${pr_target_branch}" -H "${commit_branch}" --state open --json url --jq .[].url)"
if [[ -n "${PR_URL}" ]]; then
gh pr close "${PR_URL}" -d;
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ name: Code Quality
on:
pull_request:
branches: development
push:
branches: development
workflow_dispatch:
schedule:
- cron: "0 9 * * 3"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Web API Integrada

[![CI/CD - Release][action-release-src]][action-release-href]
[![CI/CD - Generate Integrations][action-generate-integrations-src]][action-generate-integrations-href]
[![Autofix][action-autofix-src]][action-autofix-href]

## Ambientes

Expand Down Expand Up @@ -119,10 +119,10 @@ O projeto conta com um [arquivo make](./Makefile) que comporta scrips destinados
[action-release-src]: https://img.shields.io/github/actions/workflow/status/ladesa-ro/api/release.yml?style=flat&logo=github&logoColor=white&label=Release&branch=development&labelColor=18181B
[action-release-href]: https://github.com/ladesa-ro/api/actions/workflows/release.yml?query=branch%3Adevelopment

<!-- Badges / Actions / Generate Integrations -->
<!-- Badges / Actions / Autofix -->

[action-generate-integrations-src]: https://img.shields.io/github/actions/workflow/status/ladesa-ro/api/ci-generate-integrations.yml?style=flat&logo=github&logoColor=white&label=Generate%20Integrations&branch=development&labelColor=18181B
[action-generate-integrations-href]: https://github.com/ladesa-ro/api/actions/workflows/ci-generate-integrations.yml?query=branch%3Adevelopment
[action-autofix-src]: https://img.shields.io/github/actions/workflow/status/ladesa-ro/api/autofix.yml?style=flat&logo=github&logoColor=white&label=Generate%20Integrations&branch=development&labelColor=18181B
[action-autofix-href]: https://github.com/ladesa-ro/api/actions/workflows/autofix.yml?query=branch%3Adevelopment

<!-- Badges / Integrations / NPM -->

Expand Down

0 comments on commit 0392701

Please sign in to comment.