feat: add dependabot #6
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: 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: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set up Ruby | |
uses: ruby/setup-ruby@v1 | |
with: | |
ruby-version: 3 | |
bundler-cache: true | |
- name: Install jq | |
run: sudo apt-get install jq | |
- name: Extract port from cypress.json | |
id: vars | |
run: | | |
apiUrl=$(jq -r '.env.apiUrl // .baseUrl // empty' ./cypress.json) | |
if [[ -z "$apiUrl" ]]; then | |
echo "API URL or Base URL not found in cypress.json." | |
exit 1 | |
fi | |
port=$(echo $apiUrl | grep -o '[0-9]\+') | |
if [[ -z "$port" ]]; then | |
echo "Port not found in URL." | |
exit 1 | |
fi | |
echo "Extracted port: $port" | |
echo "::set-output name=port::$port" | |
- name: Run tests | |
uses: cypress-io/github-action@v5 | |
with: | |
build: npm run build | |
start: npm run start | |
wait-on: 'npx wait-on --timeout ${{ env.WAIT_ON_TIMEOUT }} tcp:${{ steps.vars.outputs.port }}' | |
env: | |
WAIT_ON_TIMEOUT: ${{ vars.WAIT_ON_TIMEOUT }} | |
# 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 jq | |
run: sudo apt-get install jq | |
- name: Extract port from cypress.json | |
id: vars | |
run: | | |
apiUrl=$(jq -r '.env.apiUrl // .baseUrl // empty' ./cypress.json) | |
if [[ -z "$apiUrl" ]]; then | |
echo "API URL or Base URL not found in cypress.json." | |
exit 1 | |
fi | |
port=$(echo $apiUrl | grep -o '[0-9]\+') | |
if [[ -z "$port" ]]; then | |
echo "Port not found in URL." | |
exit 1 | |
fi | |
echo "Extracted port: $port" | |
echo "::set-output name=port::$port" | |
- name: Run tests | |
uses: cypress-io/github-action@v5 | |
with: | |
build: npm run build | |
start: npm run start | |
wait-on: 'npx wait-on --timeout ${{ env.WAIT_ON_TIMEOUT }} tcp:${{ steps.vars.outputs.port }}' | |
env: | |
WAIT_ON_TIMEOUT: ${{ vars.WAIT_ON_TIMEOUT }} | |
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 | |
}); |