diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1e9c1be --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/app" + schedule: + interval: "daily" + labels: + - "npm" + - "dependencies" + + - package-ecosystem: "composer" + directory: "/app" + schedule: + interval: "daily" + labels: + - "dependencies" + - "php" + allow: + - dependency-type: "all" \ No newline at end of file diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml new file mode 100644 index 0000000..5b9341d --- /dev/null +++ b/.github/workflows/auto-merge.yml @@ -0,0 +1,90 @@ +name: Tests and Dependabot PR Handling + +on: + pull_request: + branches: + - master + - main + +jobs: + # Verifies the boilerplate can start and run in GitHub Actions environment + test-for-workflow: + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run tests + uses: cypress-io/github-action@v5 + with: + build: npm run build + start: npm run start + + # Verifies the boilerplate can start and run in codespace environment + test-for-codespaces: + runs-on: ubuntu-20.04 + permissions: + contents: read + packages: read + container: + image: ghcr.io/devskillshq/boilerplate-base-image:latest + credentials: + username: ${{ github.actor }} + password: ${{ secrets.github_token }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install + run: npm install + - name: Build + run: npm run build + - name: Start daemon + run: npm run start & + - name: Run tests + run: npm run test + + check-dependabot: + needs: + - test-for-workflow + - test-for-codespaces + runs-on: ubuntu-20.04 + outputs: + is_dependabot_pr: ${{ steps.dependabot-check.outputs.is_dependabot_pr }} + steps: + - id: dependabot-check + name: Check if PR is from Dependabot + run: | + echo "PR author: ${{ github.event.pull_request.user.login }}" + if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" || "${{ github.event.pull_request.user.login }}" == "dependabot-preview[bot]" ]]; then + echo "::set-output name=is_dependabot_pr::true" + else + echo "::set-output name=is_dependabot_pr::false" + fi + + auto-merge: + needs: check-dependabot + runs-on: ubuntu-20.04 + if: ${{ needs.check-dependabot.outputs.is_dependabot_pr == 'true' }} + steps: + - name: Merge pull request + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const pull_number = context.payload.pull_request.number; + await github.rest.pulls.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pull_number + }); + + - name: Delete branch + uses: actions/github-script@v5 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const branch_name = context.payload.pull_request.head.ref; + await github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: 'heads/' + branch_name + }); diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index fa35621..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Tests -on: - pull_request: - types: [opened, reopened] - push: - branches: - - '*' - - '!master' - - '!main' -jobs: - tests: - runs-on: ubuntu-20.04 - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Fetch apiUrl - run: echo ::set-output name=apiUrl::$(jq -r .env.apiUrl cypress.json)/ping - id: fetchApiUrl - - name: Run tests - uses: cypress-io/github-action@v2 - with: - build: npm run build - start: npm run start - wait-on: ${{ steps.fetchApiUrl.outputs.apiUrl }} - - name: Set result_url env var - if: always() - run: echo "result_url=http://mockbin.com/request" >> $GITHUB_ENV - - name: Set github_repo env var - if: always() - run: echo "github_repo=$GITHUB_REPOSITORY" >> $GITHUB_ENV - - uses: joelwmale/webhook-action@master - if: failure() - with: - url: ${{ env.result_url }} - body: '{"assignmentRepository": "${{ env.github_repo }}","status": "failed"}' - - uses: joelwmale/webhook-action@master - if: success() - with: - url: ${{ env.result_url }} - body: '{"assignmentRepository": "${{ env.github_repo }}","status": "passed"}'