Skip to content

Merge pull request #408 from ladesa-ro/dependabot/npm_and_yarn/dev-de… #25

Merge pull request #408 from ladesa-ro/dependabot/npm_and_yarn/dev-de…

Merge pull request #408 from ladesa-ro/dependabot/npm_and_yarn/dev-de… #25

name: "CI: Generate Integrations"
on:
push:
branches:
- development
concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
target-branch: development
generated-branch: robozinho-do-ladesa/generated-integrations
jobs:
generate-integrations:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
repository-projects: write
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Install
uses: ./.github/actions/prepare/install
with:
install-node: "true"
- id: build-integrations
name: Build integrations
run: |
pnpm exec nx run-many -t build --projects=tag:integrations
if [ "$(git diff --exit-code > /dev/null; echo $?)" -eq "1" ]; then
echo "has_changes=true" >> "$GITHUB_OUTPUT";
else
echo "has_changes=false" >> "$GITHUB_OUTPUT";
fi
- name: Retrieve GitHub App credentials
uses: actions/create-github-app-token@v1
id: app-token
if: steps.build-integrations.outputs.has_changes == 'true'
with:
app-id: ${{ secrets.LADESA_BOT_ID }}
private-key: ${{ secrets.LADESA_BOT_SECRET }}
- name: Get GitHub App User ID
id: get-user-id
if: steps.build-integrations.outputs.has_changes == 'true'
run: |
echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- name: Setup git with GitHub App name and email
if: steps.build-integrations.outputs.has_changes == 'true'
run: |
git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]'
git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>'
- name: Checkout to branch and commit changes
if: steps.build-integrations.outputs.has_changes == 'true'
run: |
(git branch -D ${{ env.generated-branch }} &>/dev/null || true);
git checkout -b ${{ env.generated-branch }};
git add -A;
git commit -m "chore: generate integrations";
- name: Force push into branch
if: steps.build-integrations.outputs.has_changes == 'true'
run: |
git push -f origin ${{ env.generated-branch }};
- name: Create or update pull request
if: steps.build-integrations.outputs.has_changes == 'true'
run: |
# source: https://github.com/cli/cli/discussions/5792#discussioncomment-10410197
PR_URL="$(gh pr list -B "${{ env.target-branch }}" -H "${{ env.generated-branch }}" --state open --json url --jq .[].url)"
# PR_REVIEWER="@ladesa-ro/backend"
NOW=$(date +'%Y-%m-%dT%H:%M:%S')
PR_TITLE="chore: generate integrations"
PR_BODY="**Job**: ${{ github.job }}.\n**Run number**: ${{ github.run_number }}.\nUpdated at: ${NOW}."
PR_BODY_FILE="/tmp/pr-body.txt"
echo -e "${PR_BODY}" > ${PR_BODY_FILE}
if [[ -n "${PR_URL}" ]]; then
echo "PR already exists -> ${PR_URL}"
gh pr edit \
"${PR_URL}" \
--title "${PR_TITLE}" \
--body-file "${PR_BODY_FILE}" \
;
else
gh pr create \
-B "${{ env.target-branch }}" \
-H "${{ env.generated-branch }}" \
--title "${PR_TITLE}" \
--body-file "${PR_BODY_FILE}" \
;
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}