diff --git a/.github/workflows/autocommit.yml b/.github/workflows/autocommit.yml new file mode 100644 index 0000000..887e181 --- /dev/null +++ b/.github/workflows/autocommit.yml @@ -0,0 +1,63 @@ +name: Autoupdate code + +on: + push: + branches: + - main + +concurrency: + group: 'autobuild' + cancel-in-progress: true + +permissions: + contents: write + +jobs: + prepare: + name: Prepare + runs-on: ubuntu-latest + outputs: + date: ${{ steps.date.outputs.date }} + steps: + - name: Get current date + id: date + run: echo "date=$(date -u +'%Y-%m-%d %H:%M UTC')" >> $GITHUB_OUTPUT + + update-and-commit: + name: ${{ matrix.name }} and Commit + needs: prepare + runs-on: ubuntu-latest + strategy: + matrix: + include: + - operation: lint:fix + name: Lint Fix + description: "Lint Autofix" + - operation: pack + name: Update dist folder + description: "Rebuild the distribution files" + max-parallel: 1 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + token: ${{ secrets.IMPRESSBOT_TOKEN }} + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Run ${{ matrix.operation }} + run: npm run ${{ matrix.operation }} + + - name: Commit and push if changes exist + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "${{ matrix.name }} ${{ needs.prepare.outputs.date }}" + commit_user_name: ImpressBot + commit_user_email: bot@impresscms.org + commit_author: ImpressBot diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index b3a72a5..2890b48 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -5,6 +5,10 @@ on: schedule: - cron: '5 4 * */3 0' +permissions: + contents: write + pull-requests: write + jobs: auto-release: runs-on: ubuntu-latest diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000..a75e871 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,39 @@ +# Based on code from https://andre.arko.net/2022/05/15/automatic-dependabot-merges/ + +name: "Merge updates" +on: + workflow_run: + workflows: + - "Tests and Checks" + types: + - "completed" + branches: + - "dependabot/**" +jobs: + merge: + name: "Merge" + runs-on: "ubuntu-latest" + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' && + github.actor == 'dependabot[bot]' + steps: + - name: "Approve pull request" + uses: "juliangruber/approve-pull-request-action@v2" + with: + github-token: "${{ secrets.IMPRESSBOT_TOKEN }}" + number: "${{ github.event.workflow_run.pull_requests[0].number }}" + + - name: "Merge pull request" + uses: "actions/github-script@v7" + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + const pullRequest = context.payload.workflow_run.pull_requests[0] + const repository = context.repo + await github.rest.pulls.merge({ + merge_method: "merge", + owner: repository.owner, + pull_number: pullRequest.number, + repo: repository.repo, + }) \ No newline at end of file diff --git a/.github/workflows/on-pull-request.yml b/.github/workflows/on-pull-request.yml deleted file mode 100644 index f7916ef..0000000 --- a/.github/workflows/on-pull-request.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: On pull request - -on: - pull_request: - branches: - - main - -jobs: - - test: - runs-on: ubuntu-latest - steps: - - name: Checkouting code... - uses: actions/checkout@v4 - - - name: Setup BATS - uses: mig4/setup-bats@v1 - with: - bats-version: 1.8.2 - - - name: Test - run: bats tests - - dependabot: - needs: - - test - permissions: - pull-requests: write - contents: write - runs-on: ubuntu-latest - # Checking the actor will prevent your Action run failing on non-Dependabot - # PRs but also ensures that it only does work for Dependabot PRs. - if: ${{ github.actor == 'dependabot[bot]' }} - steps: - # This first step will fail if there's no metadata and so the approval - # will not occur. - - name: Dependabot metadata - id: dependabot-metadata - uses: dependabot/fetch-metadata@v2.3.0 - with: - github-token: "${{ secrets.GITHUB_TOKEN }}" - # Here the PR gets approved. - - name: Approve a PR - run: gh pr review --approve "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Finally, this sets the PR to allow auto-merging for patch and minor - # updates if all checks pass - - name: Enable auto-merge for Dependabot PRs - # if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }} - run: gh pr merge --auto --squash "$PR_URL" - env: - PR_URL: ${{ github.event.pull_request.html_url }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}