Kumpulan Github Actions

Conflict Labeler (Memberi Label “conflict” di PR)

name: "Conflict Labeler"

on:
  push:
    branches: [master, staging, development]
  pull_request_target:
    types: [synchronize, opened, reopened]

jobs:
  label-conflicts:
    runs-on: self-hosted
    permissions:
      pull-requests: write
      contents: read
    steps:
      - name: Check for merge conflicts
        uses: eps1lon/actions-label-merge-conflict@v3
        with:
          dirtyLabel: "conflict"
          removeOnDirtyLabel: "ready"
          repoToken: ${{ secrets.GITHUB_TOKEN }}
          commentOnDirty: |
            This PR has merge conflicts. Please resolve them before merging.            
          commentOnClean: |
            Conflicts have been resolved. A maintainer will review the PR shortly.            

PR Auto Reply


name: PR Branch-Based Auto Reply

on:
  pull_request:
    types: [opened, reopened]

jobs:
  auto-reply:
    runs-on: self-hosted
    permissions:
      pull-requests: write
    steps:
      - name: Reply based on target branch
        uses: actions/github-script@v7
        with:
          script: |
            const baseBranch = context.payload.pull_request.base.ref;
            let message = '';

            if (baseBranch === 'development') {
              message = [
                '- Dont forget to check .env'
              ].join('\n');
            } else if (baseBranch === 'staging') {
              message = 'Dont forget to check .env and run that on your local first. Add semantic versioning on your PR title #patch, #minor, #major so it will be easier to understand what are updates do';
            } else if (baseBranch === 'master') {
              message = [
                '## **MUST ADD SEMANTIC VERSIONING**',
                '',
                '**This PR targets `master`. You MUST add a semantic versioning tag in the PR title or description before it can be merged:**',
                '',
                '- **`#patch`** — for backward-compatible bug fixes',
                '- **`#minor`** — for backward-compatible new features',
                '- **`#major`** — for breaking changes',
                '',
                '> **PRs without a semantic version tag will NOT be merged.**'
              ].join('\n');
            }

            if (message) {
              await github.rest.issues.createComment({
                issue_number: context.issue.number,
                owner: context.repo.owner,
                repo: context.repo.repo,
                body: message
              });
            }            

Stale Bot (Memberi Label “stale” di PR & Issues, Close Otomatis)

name: Stale Bot

on:
  schedule:
    - cron: '0 0 * * *' # UTC
  workflow_dispatch: # Allows manual trigger from the Actions tab

jobs:
  stale:
    runs-on: self-hosted
    permissions:
      issues: write
      pull-requests: write
    steps:
      - uses: actions/stale@v9
        with:
          days-before-pr-stale: 30
          days-before-pr-close: 7
          stale-pr-message: 'This PR has been automatically marked as stale because it has had no activity for 30 days. It will be closed in 7 days if no further activity occurs.'
          close-pr-message: 'This PR has been automatically closed because it remained stale for 7 days with no activity.'
          stale-pr-label: 'stale'
          exempt-pr-labels: 'pinned,security,in-progress'

          days-before-issue-stale: 30
          days-before-issue-close: 7
          stale-issue-message: 'This issue has been automatically marked as stale because it has had no activity for 30 days. It will be closed in 7 days if no further activity occurs.'
          close-issue-message: 'This issue has been automatically closed because it remained stale for 7 days with no activity.'
          stale-issue-label: 'stale'
          exempt-issue-labels: 'pinned,security,in-progress'

          operations-per-run: 100
          remove-stale-when-updated: true

Auto Image Remover on ghcr.io

name: 3 Version Keep Daily Image Cleanup

on:
  schedule:
    - cron: '43 19 * * *' #run in utc
  workflow_dispatch:

jobs:
  ghcr-cleanup-image:
    name: ghcr keep only several tag and keep 3 version
    runs-on: self-hosted
    steps:
      - name: Delete old images
        uses: dataaxiom/ghcr-cleanup-action@v1
        with:
          token: ${{ secrets.GHCR_CLEANUP_PAT }}   # classic PAT, see below
          owner: my-company
          packages: 'your-repo,your-repo-2'
          exclude-tags: main*,master*,development*
          keep-n-tagged: 2
          delete-untagged: true
          delete-partial-images: true
          dry-run: false