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

feature: CI/CD docs (next-major) and merges (next-major/main) #243

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
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
130 changes: 130 additions & 0 deletions .github/workflows/merge-to-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Attempt to merge next to main
on:
workflow_dispatch:

jobs:
# Check if next can merge into main
check_merge:
name: Check if "next" can merge into "main"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
repo-token: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }}
persist-credentials: true

# Set user identity
- name: Set-Identity
run: |
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"

# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "main"
- name: Checkout main
run: git checkout "main"

# Update "main" version to match "next"
- name: Update "main" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json

if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi

# Attempt a dry-run merge
- name: Attempt a dry-run merge
run: |
git merge --no-commit --no-ff origin/${{github.ref_name}}
exit $?

# Attempt to merge to main if our dry-run succeeded
process_merge_on_success:
name: Perform merge from "next" to "main"
needs: check_merge
runs-on: ubuntu-latest
if: ${{ success() }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
repo-token: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }}
persist-credentials: true

# Set user identity
- name: Set-Identity
run: |
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"

# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "main"
- name: Checkout main
run: git checkout "main"

# Update "main" version to match "next"
- name: Update "main" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json

if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi

- name: Perform the merge from next to main
run: |
git merge origin/next
merge_status=$?

git push origin "main"
push_status=$?

if [ "$merge_status" -eq 0 ] && [ "$push_status" -eq 0 ]; then
echo "Push to main succeeded"
exit 0
else
exit 1
fi

# If the merge cannot be performed, let stakeholders know
process_merge_on_failure:
name: Merge dry-run failure
needs: check_merge
runs-on: ubuntu-latest
if: ${{ failure() }}

steps:
- name: Post error message (To-Do)
run: echo "Next cannot be merged into main cleanly"

# If we attempted to merge/push to next-main but there was a failure
process_push_failure:
name: Merge failure
needs: process_merge_on_success
runs-on: ubuntu-latest
if: ${{ failure() && needs.process_merge_on_success.result != 'skipped' }}

steps:
- name: Post error message (To-Do)
run: echo "There was a failure when merging next into main"
133 changes: 133 additions & 0 deletions .github/workflows/merge-to-next-major.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
name: Attempt to merge next to next-major
on:
workflow_dispatch:
push:
branches:
- "next"

jobs:
# Check if next can merge into next-major
check_merge:
name: Check if "next" can merge into "next-major"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
repo-token: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }}
persist-credentials: true

# Set user identity
- name: Set-Identity
run: |
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"

# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

# Update "next-major" version to match "next"
- name: Update "next-major" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json

if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi

# Attempt a dry-run merge
- name: Attempt a dry-run merge
run: |
git merge --no-commit --no-ff origin/${{github.ref_name}}
exit $?

# Attempt to merge to next-major if our dry-run succeeded
process_merge_on_success:
name: Perform merge from "next" to "next-major"
needs: check_merge
runs-on: ubuntu-latest
if: ${{ success() }}

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
repo-token: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }}
persist-credentials: true

# Set user identity
- name: Set-Identity
run: |
git config --global user.email "${{ secrets.GLOBAL_GITHUB_EMAIL }}"
git config --global user.name "${{ secrets.GLOBAL_GITHUB_USER }}"

# Get the "next" version number
- name: Extract next version
id: extract_version
run: echo "::set-output name=version::$(node -e 'console.log(require("./package.json").version)')"

# Checkout "next-major"
- name: Checkout next-major
run: git checkout "next-major"

# Update "next-major" version to match "next"
- name: Update "next-major" version to match "next"
run: |
jq '.version = "${{ steps.extract_version.outputs.version }}"' package.json > temp.json

if diff -q "package.json" "temp.json" >/dev/null; then
echo "Versions are identical. No change required."
rm temp.json
else
mv temp.json package.json
git add package.json && git commit -m "Sync version to ${{ steps.extract_version.outputs.version }}"
fi

- name: Perform the merge from next to next-major
run: |
git merge origin/next
merge_status=$?

git push origin "next-major"
push_status=$?

if [ "$merge_status" -eq 0 ] && [ "$push_status" -eq 0 ]; then
echo "Push to next-major succeeded"
exit 0
else
exit 1
fi

# If the merge cannot be performed, let stakeholders know
process_merge_on_failure:
name: Merge dry-run failure
needs: check_merge
runs-on: ubuntu-latest
if: ${{ failure() }}

steps:
- name: Post error message (To-Do)
run: echo "Next cannot be merged into next-major cleanly"

# If we attempted to merge/push to next-main but there was a failure
process_push_failure:
name: Merge failure
needs: process_merge_on_success
runs-on: ubuntu-latest
if: ${{ failure() && needs.process_merge_on_success.result != 'skipped' }}

steps:
- name: Post error message (To-Do)
run: echo "There was a failure when merging next into next-major"
28 changes: 19 additions & 9 deletions .github/workflows/release-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- 'proposed'
pull_request:
types: [opened, synchronize]
branches:
branches:
- 'next'
- 'proposed'
env:
Expand All @@ -19,6 +19,7 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
# Checkout/install project
- name: Checkout
uses: actions/checkout@v2
with:
Expand All @@ -35,6 +36,8 @@ jobs:
run: 'echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc'
- name: Install dependencies
run: npm ci

# Set NPM_DIST_TAGS and DOCS_TAG if applicable based on branch
- name: Set main tags
if: github.ref_name == 'main' && github.event_name != 'pull_request'
run: |
Expand All @@ -45,17 +48,24 @@ jobs:
run: |
echo "NPM_DIST_TAG=next" >> $GITHUB_ENV
echo "DOCS_TAG=next" >> $GITHUB_ENV
- name: Set next-major tags
if: github.ref_name == 'next-major' && github.event_name != 'pull_request'
run: |
echo "NPM_DIST_TAG=next-major" >> $GITHUB_ENV
echo "DOCS_TAGE=next-major" >> $GITHUB_ENV
- name: Set feature branch tags
if: github.ref_name != 'main' && github.ref_name != 'next' && github.event_name != 'pull_request'
if: github.ref_name != 'main' && github.ref_name != 'next' && github.ref_name != 'next-major' && github.event_name != 'pull_request'
run: |
echo "NPM_DIST_TAG=test" >> $GITHUB_ENV
echo "FEATURE_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Set PR tags
if: github.ref_name != 'main' && github.ref_name != 'next' && github.event_name == 'pull_request'
if: github.ref_name != 'main' && github.ref_name != 'next' && github.ref_name != 'next-major' && github.event_name == 'pull_request'
run: |
echo "NPM_DIST_TAG=test" >> $GITHUB_ENV
echo "DOCS_TAG=pr-$(node ./src/js/version.mjs branch-to-prerelease ${{ github.head_ref }})" >> $GITHUB_ENV
echo "FEATURE_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV

# Perform real (When not a PR) or dry-run (When PR) semantic-release
- name: Release mono-artifact to GitHub
if: (github.ref_name != 'main' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch'
env:
Expand All @@ -67,7 +77,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches
run: npx semantic-release --dry-run
- name: Build artifacts for feature branches
if: github.ref_name != 'main' && github.ref_name != 'next'
if: github.ref_name != 'main' && github.ref_name != 'next' && github.ref_name != 'next-major'
run: |
PRERELEASE=$(node ./src/js/version.mjs branch-to-prerelease $FEATURE_BRANCH)
node ./src/js/version.mjs latest-prerelease $PRERELEASE
Expand All @@ -78,15 +88,15 @@ jobs:
id: check_build
uses: andstor/file-existence-action@v2
with:
files: "./src/sdks/core/dist/lib/firebolt.mjs"
files: './src/sdks/core/dist/lib/firebolt.mjs'
- name: Release Firebolt SDKs to NPM
if: steps.check_build.outputs.files_exists == 'true' && github.event_name != 'pull_request' && (github.ref_name != 'main' || github.event_name == 'workflow_dispatch')
env:
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }} # <-- Allows semantic-release to publish to npm without 2 factor auth.
run: |
npm --version
echo "NPM DIST TAG :: " $NPM_DIST_TAG
npm publish --tag $NPM_DIST_TAG --workspaces
npm --version
echo "NPM DIST TAG :: " $NPM_DIST_TAG
npm publish --tag $NPM_DIST_TAG --workspaces
- name: Dry-run Firebolt SDKs to NPM
if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' && github.event_name != 'workflow_dispatch')
env:
Expand All @@ -100,7 +110,7 @@ jobs:
cd /tmp
git clone https://rdkcentral:[email protected]/rdkcentral/firebolt.git ./firebolt-docs
- name: Release docs to GitHub.io
if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' || github.ref_name == 'next' || github.event_name == 'pull_request')
if: steps.check_build.outputs.files_exists == 'true' && (github.ref_name == 'main' || github.ref_name == 'next' || github.ref_name == 'next-major' || github.event_name == 'pull_request')
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_BOT_PAT }} # <-- Allows semantic-release-bot to push changes to protected branches
run: |
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading