diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2534841..74addd9 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,19 +1,19 @@ -version: 2 -updates: - - - package-ecosystem: npm - directory: "/" - versioning-strategy: increase-if-necessary - schedule: - interval: monthly - open-pull-requests-limit: 20 - labels: - - dependencies - - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: monthly - open-pull-requests-limit: 20 - labels: - - dependencies +version: 2 +updates: + + - package-ecosystem: npm + directory: "/" + versioning-strategy: increase-if-necessary + schedule: + interval: monthly + open-pull-requests-limit: 20 + labels: + - dependencies + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: monthly + open-pull-requests-limit: 20 + labels: + - dependencies diff --git a/.github/workflows/autocommit.yml b/.github/workflows/autocommit.yml new file mode 100644 index 0000000..ebbac20 --- /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: format + name: Format code + description: "Format code according to project standards" + - 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 3149f4e..1983ac7 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -1,17 +1,21 @@ -name: Automatic releases - -on: - workflow_dispatch: - schedule: - - cron: '5 4 * */3 0' - -jobs: - auto-release: - runs-on: ubuntu-latest - steps: - - name: Releasing if there is something new... - uses: impresscms-dev/simple-autorelease-action@v0.2 - with: - release_branch: main - github_token: ${{ secrets.GITHUB_TOKEN }} - default_bump: patch +name: Automatic releases + +on: + workflow_dispatch: + schedule: + - cron: '0 0 1 */6 *' + +permissions: + contents: write + pull-requests: write + +jobs: + auto-release: + runs-on: ubuntu-latest + steps: + - name: Releasing if there is something new... + uses: impresscms-dev/simple-autorelease-action@v0.2 + with: + release_branch: main + github_token: ${{ secrets.GITHUB_TOKEN }} + default_bump: patch 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 5a2b0cf..0000000 --- a/.github/workflows/on-pull-request.yml +++ /dev/null @@ -1,125 +0,0 @@ -name: On pull request - -on: - pull_request: - branches: - - main - -permissions: write-all - -jobs: - test: - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: - - 20.x - - steps: - - name: Checkouting code... - uses: actions/checkout@v4 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - - name: NPM install - run: npm install - - - name: NPM test - run: npm run test - - build: - - runs-on: ubuntu-latest - needs: test - - steps: - - name: Checkouting code... - uses: actions/checkout@v4 - - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v4 - with: - node-version: 20.x - - - name: NPM install - run: npm install - - - name: NPM format - run: npm run format - - - name: NPM format check - run: npm run format-check - - - name: Lint - run: npm run lint - - - name: Pack - run: npm run pack - - - name: Uploading build artifact... - uses: actions/upload-artifact@v4 - with: - name: build - path: dist/*.* - - commit_and_push: - - runs-on: ubuntu-latest - name: Commit and push build if needed - needs: build - - steps: - - name: Checkouting code... - uses: actions/checkout@v4 - - - name: Downloading build artifact.... - uses: actions/download-artifact@v4 - with: - name: build - path: dist/ - - - name: Auto commiting changes... - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: Automatically builded and updated - file_pattern: dist/*.js dist/*.json - skip_fetch: true - skip_checkout: true - - dependabot: - needs: - - build - - commit_and_push - 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 }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..19c4d1c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,53 @@ +name: Tests and Checks + +on: + pull_request: + branches: + - main + types: + - opened + - synchronize + - reopened + - ready_for_review + +permissions: + contents: write + pull-requests: write + +jobs: + validate: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - task: test + name: Run tests + command: test + - task: format-check + name: Check code formatting + command: format-check + - task: lint + name: Lint code + command: lint + - task: pack + name: Compile + command: pack + fail-fast: false + name: ${{ matrix.name }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: 'npm' + + - name: Install dependencies + run: npm install + env: + CI: true + + - name: ${{ matrix.name }} + run: npm run ${{ matrix.command }} diff --git a/package-lock.json b/package-lock.json index 0c82da1..3cfb96f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,6 @@ "packages": { "": { "name": "flattern-markdown-folder-structure-action", - "version": "1.1.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", diff --git a/package.json b/package.json index 2408567..d2f5e39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,5 @@ { "name": "flattern-markdown-folder-structure-action", - "version": "1.1.0", "description": "GitHub action to flatten file structure with markdown data", "main": "src/index.js", "type": "module", @@ -12,7 +11,7 @@ "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "format": "prettier --write **/*.js tests/**/*.js", "format-check": "prettier --check **/*.js tests/**/*.js", - "lint": "eslint src/**/*.js tests/**/*.js", + "lint": "eslint --no-warn-ignored 'src/**/*.js' 'tests/**/*.js'", "pack": "ncc build src/index.js --minify", "all": "npm install && npm run format && npm run lint && npm run pack", "fast-all": "npm install && npm run pack"