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

Create workflows to release Node.js adapter from own repo #521

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions .github/workflows/release-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Release Nightly

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:

release-nightly:
name: Nightly release
if: github.event_name != 'schedule' || github.repository == 'keycloak/keycloak-nodejs-connect'
uses: ./.github/workflows/x-release.yml
with:
gh-org: keycloak
branch: ${{ github.ref_name }}
tag: nightly
nightly: true
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release

on:
workflow_dispatch:
inputs:
version:
description: Release version
required: true

jobs:

release:
name: Release
uses: ./.github/workflows/x-release.yml
with:
gh-org: keycloak
branch: ${{ github.ref_name }}
tag: ${{ inputs.version }}
nightly: false
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
107 changes: 107 additions & 0 deletions .github/workflows/x-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: X Release

on:
workflow_call:
inputs:
gh-org:
required: true
type: string
branch:
required: true
type: string
tag:
required: true
type: string
nightly:
required: true
type: boolean
secrets:
NPM_TOKEN:
required: false

concurrency: rel-${{ github.ref }}

defaults:
run:
shell: bash

jobs:

release-impl:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
check-latest: true
registry-url: https://registry.npmjs.org

- name: Create version commit
jonkoops marked this conversation as resolved.
Show resolved Hide resolved
if: ${{ !inputs.nightly }}
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
npm version ${{ inputs.tag }} -m "Set version to ${{ inputs.tag }}"

- name: Tag commit
run: git tag ${{ inputs.tag }}

- name: Push changes
run: git push --force origin refs/tags/${{ inputs.tag }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would only push the tag right? Don't we also want to push the commit itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit itself is pushed just into the tag. But it is not pushed to the main branch (or release/X.Y branch) itself. I think it is done intentionally that way and it is the approach used in all Keycloak repositories.

For example last commit in the 26.0.7 tag contains the version commit: https://github.com/keycloak/keycloak-nodejs-connect/commits/26.0.7/ .

But the release/26.0 branch itself, from which the tag was created, does not contain that version commit: https://github.com/keycloak/keycloak-nodejs-connect/commits/release/26.0 .

I prefer to be consistent with other Keycloak repositories and hence keep put the version commit just to the tag. Or did you mean something different?


- name: Check if release exists
id: release-exists
run: >
echo "release-exists=$(
if ( gh release view ${{ inputs.tag }} --repo ${{ inputs.gh-org }}/keycloak-nodejs-connect &> /dev/null ); then
echo 'true'
else
echo 'false'
fi
)" >> "$GITHUB_OUTPUT"

- name: Create a github release
if: steps.release-exists.outputs.release-exists == 'false'
run: gh release create ${{ inputs.tag }} --repo ${{ inputs.gh-org }}/keycloak-nodejs-connect --title ${{ inputs.tag }} --draft ${{ inputs.nightly && '--prerelease' || '' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create package tarball
run: |
npm pack
mv -T *.tgz keycloak-nodejs-connect.tgz

- name: Upload to GitHub Releases
run: |
for i in `gh release view ${{ inputs.tag }} --json assets --jq '.assets[].name'`; do
test -f $i || gh release delete-asset ${{ inputs.tag }} $i -y
done
gh release upload ${{ inputs.tag }} keycloak-nodejs-connect.tgz --clobber
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish release
run: gh release edit ${{ inputs.tag }} --repo ${{ inputs.gh-org }}/keycloak-nodejs-connect --draft=false
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Show Output Github
run: |
echo "https://github.com/${{ inputs.gh-org }}/keycloak-nodejs-connect/tree/${{ inputs.tag }} " >> $GITHUB_STEP_SUMMARY
echo "https://github.com/${{ inputs.gh-org }}/keycloak-nodejs-connect/releases/tag/${{ inputs.tag }} " >> $GITHUB_STEP_SUMMARY

- name: Publish to NPM
if: ${{ !inputs.nightly }}
run: npm publish keycloak-nodejs-connect.tgz --access public --ignore-scripts ${{ inputs.gh-org != 'keycloak' && ' --dry-run' || '' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Show Output NPM
if: ${{ !inputs.nightly && inputs.gh-org == 'keycloak' }}
run: echo "https://www.npmjs.com/package/keycloak-connect/v/${{ inputs.tag }} " >> $GITHUB_STEP_SUMMARY
23 changes: 0 additions & 23 deletions release.sh

This file was deleted.

Loading