Skip to content

Commit

Permalink
Merge branch 'main' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehonal authored Aug 2, 2023
2 parents 871c09e + 88f87e4 commit ba27a84
Show file tree
Hide file tree
Showing 4 changed files with 543 additions and 19 deletions.
27 changes: 24 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ on:
# - labeled
#
# pull_request_target -> GITHUB_TOKEN has write permissions external forks
pull_request_target:
pull_request:
types:
- labeled
- unlabeled

env:
NODE_VERSION: 16
Expand All @@ -18,14 +19,15 @@ permissions:
pull-requests: write

jobs:
version-bump:
version-bump-test-1:
if: github.event.label.name == 'pr-version-bump'
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Test bump action
with:
user_name: 'drassil-git-bot'
Expand All @@ -35,6 +37,25 @@ jobs:
node_version: ${{ env.NODE_VERSION }}
uses: ./

- name: Test restore action
with:
user_name: 'drassil-git-bot'
user_email: '[email protected]'
ref_branch: 'main'
version_args: 'patch'
node_version: ${{ env.NODE_VERSION }}
action: 'restore'
uses: ./

version-bump-test-2:
if: github.event.label.name == 'pr-version-bump'
runs-on: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}

- name: Test bump action (without push)
with:
user_name: 'drassil-git-bot'
Expand Down
48 changes: 46 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ inputs:
required: true
type: boolean
default: false
action:
description: 'Action to perform: "bump" or "restore"'
required: true
default: 'bump'


runs:
using: 'composite'
steps:
Expand All @@ -47,13 +53,19 @@ runs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
token: ${{ inputs.access_token || github.token }}
- name: Pull and bump version

- name: Git configure
shell: bash
run: |
git remote add main-repo https://github.com/${{ inputs.repository || github.repository }}
git config remote.main-repo.url >&- || git remote add main-repo https://github.com/${{ inputs.repository || github.repository }}
git config --global user.name ${{ inputs.user_name }}
git config --global user.email ${{ inputs.user_email }}
git config --global pull.rebase ${{ inputs.use_rebase }}
- name: Pull and bump version
shell: bash
if: inputs.action == 'bump'
run: |
git pull main-repo ${{ inputs.ref_branch }}
echo "Updating version"
npm version --no-git-tag-version ${{ inputs.version_args }}
Expand All @@ -66,6 +78,38 @@ runs:
echo "Creating commit and pushing"
git add -A
git commit -m "chore: bump package version to $PACKAGE_VERSION and update changelog"
- name: Restore
env:
GH_TOKEN: ${{ inputs.access_token || github.token }}
if: inputs.action == 'restore'
shell: bash
run: |
set -x
# Get the name of the target branch
target_branch=$(gh pr view ${{ github.event.pull_request.number }} --json baseRefName -q '.baseRefName')
# Fetch the target branch
git fetch main-repo $target_branch:$target_branch
# Get the last common commit of the current PR branch and the target branch
common_commit=$(git merge-base HEAD $target_branch)
# Get the version of the package from the common commit
target_version=$(git show $common_commit:package.json | jq -r '.version')
# Update the version of the package in the current branch
jq ".version = \"$target_version\"" package.json > temp.json && mv temp.json package.json
# Replace the CHANGELOG.md content with the content of the CHANGELOG.md from the common commit
git show $common_commit:CHANGELOG.md > CHANGELOG.md
npm install --package-lock-only
git add -A
git commit -m "chore: restore package version to $target_version and restored changelog"
- name: Push
if: ${{ inputs.skip_push != 'true' }}
shell: bash
Expand Down
Loading

0 comments on commit ba27a84

Please sign in to comment.