-
Notifications
You must be signed in to change notification settings - Fork 3
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
ci: Automated lib version bumping #213
Open
scott45
wants to merge
2
commits into
dev
Choose a base branch
from
automated-lib-version-bumping
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Publish package to GitHub Packages | ||
on: | ||
push: | ||
branches: [ "dev" ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
|
||
build-and-publish: | ||
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Setup .npmrc file to publish to GitHub Packages | ||
- name: Setup Node.js (.npmrc) | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://npm.pkg.github.com' | ||
# Defaults to the user or organization that owns the workflow file | ||
scope: 'tazama-lf' | ||
|
||
- name: Version prerelease | ||
run: npm version prerelease | ||
env: | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
env: | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
|
||
- name: Publish package | ||
run: npm publish | ||
env: | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
NODE_AUTH_TOKEN: '${{ secrets.NODE_AUTH_TOKEN }}' | ||
|
||
sync-version-across-tazama-repos: | ||
if: github.event.pull_request.merged == true | ||
runs-on: ubuntu-latest | ||
needs: build-and-publish | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get the new Verion and store it as a variable | ||
run: NEW_VERSION=$(npm pkg get version --workspaces=false | tr -d \") | ||
|
||
- name: update frms-coe-lib version across tazama-lf org repos in dev | ||
env: | ||
BRANCH: sync-frms-coe-lib-version-dev | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
PR_REVIEWERS: | | ||
rtkay123 | ||
# Lenbkr | ||
# Justus-at-Tazama | ||
cshezi | ||
# JeanPierreNell | ||
scott45 | ||
REPOS: | # List of repositories to have version updated | ||
# relay-service | ||
rule-901 | ||
# typology-processor | ||
# channel-router-setup-processor | ||
# event-sidecar | ||
# lumberjack | ||
# nats-utilities | ||
# batch-ppa | ||
# admin-service | ||
# payment-platform-adapter | ||
rule-executer | ||
# tms-service | ||
# transaction-aggregation-decisioning-processor | ||
frms-coe-startup-lib | ||
run: | | ||
for repo in $REPOS; do | ||
git clone https://github.com/frmscoe/$repo.git | ||
cd $repo | ||
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/frmscoe/$repo.git | ||
|
||
if git ls-remote --heads origin "${{ env.branch }}" | grep "${{ env.branch }}"; then | ||
# Branch exists, pull the latest changes | ||
git checkout "${{ env.branch }}" | ||
git pull origin "${{ env.branch }}" | ||
else | ||
# Branch does not exist, create it | ||
git checkout -b "${{ env.branch }}" | ||
fi | ||
|
||
sed -i 's/"version": "[^"]*"/"version": "$NEW_VERSION"/' package.json | ||
|
||
if [[ `git status --porcelain=v1 2>/dev/null | wc -l` == 0 ]]; then | ||
echo "no diff detected, exiting..." | ||
exit 0; | ||
fi | ||
|
||
git add -A | ||
git commit -m "chore: update frms-coe-lib to $NEW_VERSION" || exit 0 | ||
git push origin "${{ env.branch }}" | ||
|
||
# Clear the GITHUB_TOKEN environment variable and use a temporary file for gh authentication | ||
echo "${{ secrets.GH_TOKEN }}" > /tmp/gh_token | ||
unset GITHUB_TOKEN | ||
gh auth login --with-token < /tmp/gh_token | ||
|
||
# Create the PR with reviewers | ||
IFS=',' read -ra REVIEWERS <<< "${PR_REVIEWERS}" | ||
REVIEWERS_ARGS="" | ||
for reviewer in "${REVIEWERS[@]}"; do | ||
REVIEWERS_ARGS+="--reviewer $reviewer " | ||
done | ||
|
||
gh pr create --title "chore: update frms-coe-lib to $NEW_VERSION in $repo" --body "update frms-coe-lib to $NEW_VERSION based on [this pull request](https://github.com/tazama-lf/frms-coe-lib/pull/$PR_NUMBER)" --base dev --head "${{ env.branch }}" $REVIEWERS_ARGS || echo "PR already exists, updating existing PR" | ||
|
||
# Cleanup | ||
rm /tmp/gh_token | ||
|
||
cd .. | ||
done | ||
|
||
- name: update frms-coe-lib version across frmscoe org repos in dev | ||
env: | ||
BRANCH: sync-frms-coe-lib-version-dev | ||
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
PR_REVIEWERS: | | ||
rtkay123 | ||
Lenbkr | ||
Justus-at-Tazama | ||
cshezi | ||
JeanPierreNell | ||
scott45 | ||
REPOS: | # List of repositories to have version updated | ||
rule-001 | ||
# rule-002 | ||
# rule-003 | ||
# rule-004 | ||
# rule-006 | ||
# rule-007 | ||
# rule-008 | ||
# rule-010 | ||
# rule-011 | ||
# rule-016 | ||
# rule-017 | ||
# rule-018 | ||
# rule-020 | ||
# rule-021 | ||
# rule-024 | ||
# rule-025 | ||
# rule-026 | ||
# rule-027 | ||
# rule-028 | ||
# rule-030 | ||
# rule-044 | ||
# rule-045 | ||
# rule-048 | ||
# rule-054 | ||
# rule-063 | ||
# rule-074 | ||
# rule-075 | ||
# rule-076 | ||
# rule-078 | ||
# rule-083 | ||
# rule-084 | ||
# rule-090 | ||
# rule-091 | ||
run: | | ||
for repo in $REPOS; do | ||
git clone https://github.com/frmscoe/$repo.git | ||
cd $repo | ||
git remote set-url origin https://x-access-token:${{ secrets.GH_TOKEN }}@github.com/frmscoe/$repo.git | ||
|
||
if git ls-remote --heads origin "${{ env.branch }}" | grep "${{ env.branch }}"; then | ||
# Branch exists, pull the latest changes | ||
git checkout "${{ env.branch }}" | ||
git pull origin "${{ env.branch }}" | ||
else | ||
# Branch does not exist, create it | ||
git checkout -b "${{ env.branch }}" | ||
fi | ||
|
||
sed -i 's/"version": "[^"]*"/"version": "$NEW_VERSION"/' package.json | ||
|
||
if [[ `git status --porcelain=v1 2>/dev/null | wc -l` == 0 ]]; then | ||
echo "no diff detected, exiting..." | ||
exit 0; | ||
fi | ||
|
||
git add -A | ||
git commit -m "chore: update frms-coe-lib to $NEW_VERSION" || exit 0 | ||
git push origin "${{ env.branch }}" | ||
|
||
# Clear the GITHUB_TOKEN environment variable and use a temporary file for gh authentication | ||
echo "${{ secrets.GH_TOKEN }}" > /tmp/gh_token | ||
unset GITHUB_TOKEN | ||
gh auth login --with-token < /tmp/gh_token | ||
|
||
# Create the PR with reviewers | ||
IFS=',' read -ra REVIEWERS <<< "${PR_REVIEWERS}" | ||
REVIEWERS_ARGS="" | ||
for reviewer in "${REVIEWERS[@]}"; do | ||
REVIEWERS_ARGS+="--reviewer $reviewer " | ||
done | ||
|
||
gh pr create --title "chore: update frms-coe-lib to $NEW_VERSION in $repo" --body "update frms-coe-lib to $NEW_VERSION based on [this pull request](https://github.com/tazama-lf/frms-coe-lib/pull/$PR_NUMBER)" --base dev --head "${{ env.branch }}" $REVIEWERS_ARGS || echo "PR already exists, updating existing PR" | ||
|
||
# Cleanup | ||
rm /tmp/gh_token | ||
|
||
cd .. | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
name: Publish package to GitHub Packages | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-and-publish: | ||
if: github.actor != 'dependabot[bot]' && github.actor != 'dependabot-preview[bot]' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
# Setup .npmrc file to publish to GitHub Packages | ||
- name: Setup Node.js (.npmrc) | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20.x' | ||
registry-url: 'https://npm.pkg.github.com' | ||
# Defaults to the user or organization that owns the workflow file | ||
scope: 'tazama-lf' | ||
|
||
- name: Install dependencies | ||
run: npm ci | ||
env: | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
|
||
- name: Build library | ||
run: npm run build | ||
|
||
- name: Publish package | ||
run: npm publish | ||
env: | ||
GH_TOKEN: '${{ secrets.GH_TOKEN }}' | ||
NODE_AUTH_TOKEN: '${{ secrets.GH_TOKEN }}' |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use dependabot instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rtkay123 is this something we're currently doing? I don't think I've seen dependabot being used for this use case but I'd like to if we're doing this.
Let us wait for what @cshezi thinks, I did have a chat with him on Friday before making these changes.
Context:
The
frms-coe-lib
andfrms-coe-startup-lib
versions don't reflect correctly in most rule processors except 901. If I also remember well, before the last release we manually created PRs to do the version bumping and all.Briefly what these changes will do is ensure every time new versions of
frms-coe-lib
andfrms-coe-startup-lib
are published, a PR will be created in each repo that lists the lib as a dependency inpackage.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not currently doing that, but the change in my opinion should be in the dependabot config so that it's able to update
frms-coe-lib
andfrms-coe-startup-lib
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to look into this today