Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] pr branch name #36

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions .github/workflows/ci-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,38 @@ on:
branches:
- main
# Triggered only when package.json is modified
# paths:
# - 'package.json'
paths:
- 'package.json'
# Triggered only the PR is merged
types: [opened, synchronize, reopened, closed]

jobs:
# Add timestamp
timestamp:
runs-on: ubuntu-latest
# Trigger the workflow only if the PR is from dev branch
# if: ${{ github.event.pull_request.head.repo.full_name == 'dev2' }}
outputs:
PR_BRANCH_NAME: ${{ steps.get_pr_branch_name.outputs.PR_BRANCH_NAME }}
steps:
- name: Generate timestamp
run: |
echo "TIMESTAMP=$(TZ='America/Los_Angeles' date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
echo ${{ github.event.pull_request.head.repo.full_name }}
echo ${{ github.head_ref }}

- name: Print timestamp
run: |
echo "Execution time (Pacific Time Zone): $TIMESTAMP"

- name: Get PR branch name
id: get_pr_branch_name
run: |
echo "PR_BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_OUTPUT

# Parse version from main branch
parse-package-version-main:
runs-on: ubuntu-latest
needs: timestamp
# Trigger the workflow only if the PR is from dev branch
if: ${{ github.event.pull_request.head.repo.full_name == 'dev2' }}
if: ${{ needs.timestamp.outputs.PR_BRANCH_NAME == 'dev' }}
outputs:
MAIN_VERSION: ${{ steps.parse_package_json.outputs.MAIN_VERSION }}
steps:
Expand All @@ -47,14 +52,13 @@ jobs:
run: |
content=$(cat package.json)
echo "MAIN_VERSION=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
echo "MAIN_VERSION=$MAIN_VERSION"

# Parse version from dev branch
parse-package-version-dev:
runs-on: ubuntu-latest
needs: timestamp
# Trigger the workflow only if the PR is from dev branch
if: ${{ github.event.pull_request.head.repo.full_name == 'dev2' }}
if: ${{ needs.timestamp.outputs.PR_BRANCH_NAME == 'dev' }}
outputs:
DEV_VERSION: ${{ steps.parse_package_json.outputs.DEV_VERSION }}
steps:
Expand All @@ -69,14 +73,22 @@ jobs:
run: |
content=$(cat package.json)
echo "DEV_VERSION=$(echo $content | jq -r '.version')" >> $GITHUB_OUTPUT
echo "DEV_VERSION=$DEV_VERSION"

build-test-publish:
runs-on: ubuntu-latest
needs: [parse-package-version-main, parse-package-version-dev]
needs: [timestamp, parse-package-version-main, parse-package-version-dev]
# Trigger the workflow only if the PR is from dev branch, and DEV_VERSION is different from MAIN_VERSION
if: github.event.pull_request.head.repo.full_name == 'dev2' && needs.parse-package-version-main.outputs.MAIN_VERSION != needs.parse-package-version-dev.outputs.DEV_VERSION
if: ${{ needs.timestamp.outputs.PR_BRANCH_NAME == 'dev' }} && needs.parse-package-version-main.outputs.MAIN_VERSION != needs.parse-package-version-dev.outputs.DEV_VERSION
steps:
- name: QA Check
run: |
echo "MAIN_VERSION=${{ needs.parse-package-version-main.outputs.MAIN_VERSION }}"
echo "DEV_VERSION=${{ needs.parse-package-version-dev.outputs.DEV_VERSION }}"
if [ "${{ needs.parse-package-version-main.outputs.MAIN_VERSION }}" == "${{ needs.parse-package-version-dev.outputs.DEV_VERSION }}" ]; then
echo "QA Check failed: MAIN_VERSION and DEV_VERSION are the same"
exit 1
fi

- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

Expand Down
Loading