diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8400fa7..f01a099 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ name: Release on: push: branches: - - master + - main jobs: release: @@ -17,7 +17,7 @@ jobs: release-version-minor: ${{ steps.release.outputs.release-version-minor }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - id: release name: semantic-release uses: ahmadnassri/action-semantic-release@v1 @@ -44,4 +44,5 @@ jobs: repo: context.repo.repo } await github.git.deleteRef({ ...repo, ref: tag }).catch(() => {}) - await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA }) \ No newline at end of file + await github.git.createRef({ ...repo, ref: `refs/${tag}` , sha: process.env.GITHUB_SHA }) + diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml new file mode 100644 index 0000000..72fd760 --- /dev/null +++ b/.github/workflows/sync-upstream.yml @@ -0,0 +1,25 @@ +name: Sync Upstream + +permissions: write-all # grant write permission + +on: + schedule: + - cron: '0 0 * * 1' # scheduled for 00:00 every Monday + workflow_dispatch: # trigger manually + +jobs: + sync-upstream: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + ref: master # set the branch to merge to + fetch-depth: 0 + - name: Sync Upstream + uses: zhangnew/sync-upstream@v1 + with: + upstream: exions/merge-upstream # set the upstream repo + upstream-branch: master # set the upstream branch to merge from + branch: master # set the branch to merge to + diff --git a/.releaserc b/.releaserc deleted file mode 100644 index 946b62f..0000000 --- a/.releaserc +++ /dev/null @@ -1,35 +0,0 @@ -{ - "plugins": [ - ["@semantic-release/commit-analyzer", { - "preset": "conventionalcommits", - "releaseRules": [ - { "breaking": true, "release": "major" }, - { "revert": true, "release": "patch" }, - { "type": "build", "release": "patch" }, - { "type": "docs", "release": "patch" }, - { "type": "feat", "release": "minor" }, - { "type": "fix", "release": "patch" }, - { "type": "perf", "release": "patch" }, - { "type": "refactor", "release": "patch" } - ] - }], - ["@semantic-release/release-notes-generator", { - "preset": "conventionalcommits", - "presetConfig": { - "types": [ - { "type": "build", "section": "Build", "hidden": false }, - { "type": "chore", "section": "Chores", "hidden": false }, - { "type": "ci", "section": "CI/CD", "hidden": false }, - { "type": "docs", "section": "Docs", "hidden": false }, - { "type": "feat", "section": "Features", "hidden": false }, - { "type": "fix", "section": "Bug Fixes", "hidden": false }, - { "type": "perf", "section": "Performance", "hidden": false }, - { "type": "refactor", "section": "Refactor", "hidden": false }, - { "type": "style", "section": "Code Style", "hidden": false }, - { "type": "test", "section": "Tests", "hidden": false } - ] - } - }], - "@semantic-release/github" - ] -} \ No newline at end of file diff --git a/README.md b/README.md index a893db9..5ecf200 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,57 @@ -# Merge Upstream -Merge changes from an upstream repository branch into a current repository branch. For example, updating changes from the repository that was forked from. +# Sync Upstream + +Sync changes from an upstream repository branch into a current repository branch. For example, updating changes from the repository that was forked from. Current limitations: - only merge only selected branch - only work with public upstream Github repository -- merge fast forward only (--ff-only) +- command is `git rebase upstream/branch` -To merge multiple branches, create multiple jobs. - -To run action for another repository, create a [personal access token (PAT)](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) -```yaml - - name: Merge Upstream - uses: exions/merge-upstream@v1 - with: - upstream: ${{ github.event.inputs.upstream }} - upstream-branch: ${{ github.event.inputs.upstream-branch }} - branch: ${{ github.event.inputs.branch }} - token: ${{ secrets.TOKEN }} -``` +To sync multiple branches, create multiple jobs. ## Usage ### Set up for scheduled trigger +copy and commit this to `.github/workflows/sync-upstream.yml` in your default branch of your repository. + ```yaml -name: Scheduled Merge Remote Action +name: Sync Upstream + +permissions: write-all # grant write permission + on: schedule: - - cron: '0 0 * * 1' - # scheduled for 00:00 every Monday + - cron: '0 0 * * 1' # scheduled for 00:00 every Monday + workflow_dispatch: # trigger manually jobs: - merge-upstream: + sync-upstream: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: upstream # set the branch to merge to fetch-depth: 0 - - name: Merge Upstream - uses: exions/merge-upstream@v1 + - name: Sync Upstream + uses: zhangnew/sync-upstream@v1 with: upstream: owner/repo # set the upstream repo upstream-branch: master # set the upstream branch to merge from branch: upstream # set the branch to merge to # set up another job to merge another branch - merge-upstream-another-branch: + sync-upstream-another-branch: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: ref: another-branch # set the branch to merge to fetch-depth: 0 - - name: Merge Upstream - uses: exions/merge-upstream@v1 + - name: Sync Upstream + uses: zhangnew/sync-upstream@v1 with: upstream: owner/repo # set the upstream repo upstream-branch: another-branch # set the upstream branch to merge from @@ -64,58 +59,7 @@ jobs: ``` - - Reference: - [Triggering a workflow with events](https://docs.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow#triggering-a-workflow-with-events) - [Creating a composite run steps action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-run-steps-action) -## How to run this action manually - -This action can trigger manually as needed. - -1. Go to `Actions` at the top of your Github repository -2. Click on `Manual Merge Upstream Action` (or other name you have given) under `All workflows` -3. You will see `Run workflow`, click on it -4. Fill in the upstream repository and branch to merge from, and the branch to merge to (⚠️ double check all are correct) -5. Click `Run workflow` -6. Check your branch commit history - -### Set up for manual trigger -copy and commit this to `.github/workflows/merge-upstream.yml` in your default branch of your repository. - -```yaml -name: Manual Merge Remote Action -on: - workflow_dispatch: - inputs: - upstream: - description: 'Upstream repository owner/name. Eg. exions/merge-upstream' - required: true - default: 'owner/name' # set the upstream repo - upstream: - description: 'Upstream branch to merge from. Eg. master' - required: true - default: 'master' # set the upstream branch to merge from - branch: - description: 'Branch to merge to' - required: true - default: 'upstream' # set the branch to merge to - -jobs: - merge-upstream: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - ref: ${{ github.event.inputs.branch }} - fetch-depth: 0 - - name: Merge Upstream - uses: exions/merge-upstream@v1 - with: - upstream: ${{ github.event.inputs.upstream }} - upstream-branch: ${{ github.event.inputs.upstream-branch }} - branch: ${{ github.event.inputs.branch }} - token: ${{ secrets.TOKEN }} -``` diff --git a/action.yml b/action.yml index 24c1643..9a6097c 100644 --- a/action.yml +++ b/action.yml @@ -1,25 +1,33 @@ -name: "Merge Upstream" -description: "Merge changes from the uppstream repo you had forked from." -author: "eXions" +name: "Sync Upstream" +description: "Sync changes from the uppstream repo you had forked from." +author: "zhangnew" branding: icon: git-merge - color: black + color: green inputs: + username: + description: "User name - required for git commits" + default: "sync-upstream-bot" + useremail: + description: "User email - required for git commits" + default: "bot@github.com" upstream: - description: 'Upstream repository owner/name. For example, exions/merge-upstream' + description: "Upstream repository owner/name. For example, zhangnew/sync-upstream" + default: "master" required: true upstream-branch: - description: 'Upstream branch to merge from. For example, master' - default: 'master' + description: "Upstream branch to merge from. For example, master" + default: "master" + required: true branch: - description: 'Branch to merge to. For example, master' - default: 'master' + description: "Branch to merge to. For example, master" + default: "master" + required: true token: description: > Personal access token (PAT) used to fetch the repository. The PAT is configured - with the local git config, which enables your scripts to run authenticated git - commands. The post-job step removes the PAT. + with the local git config, which enables your scripts to run authenticated git commands. The post-job step removes the PAT. We recommend using a service account with the least permissions necessary. Also when generating a new PAT, select the least scopes necessary. [Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) @@ -27,13 +35,17 @@ inputs: runs: using: "composite" - steps: - - run: | + steps: + - run: | + set -x git remote add -f upstream "https://github.com/${{ inputs.upstream }}.git" git remote -v git branch --all + git config user.email "${{ inputs.useremail }}" + git config user.name "${{ inputs.username }}" git config --list git checkout ${{ inputs.branch }} - git merge --ff-only upstream/${{ inputs.upstream-branch }} - git push + git rebase upstream/${{ inputs.upstream-branch }} + git pull --rebase + git push shell: bash diff --git a/package.json b/package.json deleted file mode 100644 index 87fb042..0000000 --- a/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "private": true, - "name": "merge-upstream", - "version": "0.0.0-semantically-released", - "author": { - "name": "lcenchew", - "email": "lcenchew@outlook.com", - "url": "https://github.com/exions/merge-upstream" - }, - "license": "MIT", - "dependencies": { - }, - "devDependencies": { - } - } \ No newline at end of file