From 4ed55614ba17411bc54090e4d2f2ee5cfe833752 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 30 Jan 2021 21:26:56 -0500 Subject: [PATCH] Initial commit. --- .github/ISSUE_TEMPLATE.md | 10 ++++ .github/workflows/rebase.yml | 18 +++++++ .github/workflows/sync-release-version.yml | 27 +++++++++++ .github/workflows/test.yml | 55 ++++++++++++++++++++++ .gitignore | 2 + CONTRIBUTING.md | 0 Dockerfile | 9 ++++ HISTORY.md | 7 +++ LICENSE | 22 +++++++++ README.md | 47 ++++++++++++++++++ action.yml | 24 ++++++++++ 11 files changed, 221 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/workflows/rebase.yml create mode 100644 .github/workflows/sync-release-version.yml create mode 100644 .github/workflows/test.yml create mode 100644 .gitignore create mode 100644 CONTRIBUTING.md create mode 100644 Dockerfile create mode 100644 HISTORY.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..af83057 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,10 @@ +* pg-dump: + +### Description + +Describe what you were trying to get done. +Tell us what happened, what went wrong, and what you expected to happen. + +### What I Did + +Add some details about your workflow ? diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..4dbe62a --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,18 @@ +name: Automatic Rebase +on: + issue_comment: + types: [created] +jobs: + rebase: + name: Rebase + if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + token: ${{ secrets.PAT_TOKEN }} + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + - name: Automatic Rebase + uses: cirrus-actions/rebase@1.4 + env: + GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/sync-release-version.yml b/.github/workflows/sync-release-version.yml new file mode 100644 index 0000000..3ad1643 --- /dev/null +++ b/.github/workflows/sync-release-version.yml @@ -0,0 +1,27 @@ +name: Update release version. +on: + release: + types: [published] + + +jobs: + update-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Bumpversion release version + uses: tj-actions/bumpversion@v7.1 + id: bumpversion + with: + pattern: 'tj-actions/pg-dump@' + paths: | + README.md + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + base: "main" + title: "Upgraded to ${{ steps.bumpversion.outputs.new_version }}" + branch: "upgrade-to-${{ steps.bumpversion.outputs.new_version }}" + commit-message: "Upgraded from ${{ steps.bumpversion.outputs.old_version }} -> ${{ steps.bumpversion.outputs.new_version }}" + body: "View [CHANGES](https://github.com/${{ github.repository }}/compare/${{ steps.bumpversion.outputs.old_version }}...${{ steps.bumpversion.outputs.new_version }})" + token: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..93fb968 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,55 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + name: Test postgres-restore + services: + postgres: + image: postgres:9.6 + env: + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_user_password + POSTGRES_DB: testdb + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Run pg_dump + uses: ./ + with: + database_url: "postgres://test_user:test_user_password@localhost:5432/testdb" + path: "backups/backup.sql" + + - name: Check changes to backup file. + id: changed_backup + uses: tj-actions/verify-changed-files@v5.1 + with: + files: backups/backup.sql + + - name: Commit changes to backup file. + if: steps.changed_backup.outputs.files_changed == 'true' + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git add backups/backup.sql + git commit -m "Auto update backup.sql." + + - name: Push changes + if: steps.changed_backup.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ secrets.PAT_TOKEN }} + branch: ${{ github.head_ref }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a53c681 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +.envrc diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7a54e9f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.13.0 + +LABEL maintainer="Tonye Jack " + +RUN apk add bash + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/HISTORY.md b/HISTORY.md new file mode 100644 index 0000000..9beff45 --- /dev/null +++ b/HISTORY.md @@ -0,0 +1,7 @@ +History +------- + +v1 (2021-01-30) +------------------ + +* Initial Release. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c5778c --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2021, Tonye Jack + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..f10e2e6 --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +pg-dump +------- + +Run pg_dump to generate a backup + +```yaml +... + steps: + - uses: actions/checkout@v2 + - name: Postgres Dump Backup + uses: tj-actions/pg-dump@v1 +``` + + +## Inputs + +| Input | type | required | default | description | +|:-------------:|:-----------:|:-------------:|:----------------------------:|:-------------:| +| token | `string` | `true` | `${{ github.token }}` | [GITHUB_TOKEN](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow#using-the-github_token-in-a-workflow)
or a repo scoped
[Personal Access Token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) | + + + +* Free software: [MIT license](LICENSE) + +Features +-------- + +* TODO + + +Credits +------- + +This package was created with [Cookiecutter](https://github.com/cookiecutter/cookiecutter). + + + +Report Bugs +----------- + +Report bugs at https://github.com/tj-actions/pg-dump/issues. + +If you are reporting a bug, please include: + +* Your operating system name and version. +* Any details about your workflow that might be helpful in troubleshooting. +* Detailed steps to reproduce the bug. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..3c2affd --- /dev/null +++ b/action.yml @@ -0,0 +1,24 @@ +name: Postgres Dump Backup +description: Run pg_dump to generate a backup +author: tj-actions +inputs: + database_url: + description: 'Database URL' + required: true + path: + description: 'Backup file output location' + required: true + args: + description: 'Extra arguments passed to pg_dump' + required: true + default: '-O' + +runs: + using: 'composite' + steps: + - run: | + pg_dump "${{ inputs.args }}" -d "${{ inputs.database_url }}" > "${{ inputs.path }}" + shell: bash +branding: + icon: hard-drive + color: white