|
| 1 | +name: 🚀 Publish ExTester |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + description: "Version tag to publish (vX.X.X)" |
| 8 | + required: true |
| 9 | + skipPublish: |
| 10 | + description: "Skip publish into NPM registry (npmjs)" |
| 11 | + default: false |
| 12 | + type: boolean |
| 13 | + skipPackageJsonMatch: |
| 14 | + description: "Skip tag validation with package.json (testing)" |
| 15 | + default: false |
| 16 | + type: boolean |
| 17 | + draft: |
| 18 | + description: "Publish GH release as draft" |
| 19 | + default: false |
| 20 | + type: boolean |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + build-and-publish: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: 🔖 Show input tag |
| 31 | + run: echo "Publishing version ${{ github.event.inputs.tag }}" |
| 32 | + |
| 33 | + - name: 👷🏻 Checkout Repository |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: ✅ Verify Git tag exists |
| 39 | + run: | |
| 40 | + git fetch --tags |
| 41 | + if ! git rev-parse "refs/tags/${{ github.event.inputs.tag }}" >/dev/null 2>&1; then |
| 42 | + echo "❌ Tag '${{ github.event.inputs.tag }}' does not exist!" |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + - name: ✅ Validate and extract tag |
| 47 | + run: | |
| 48 | + TAG=${{ github.event.inputs.tag }} |
| 49 | + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 50 | + echo "❌ Invalid tag format: $TAG. Use format like 'v1.2.3'" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 54 | + echo "VERSION=${TAG#v}" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: ✅ Ensure tag matches package.json version |
| 57 | + if: ${{ github.event.inputs.skipPackageJsonMatch != 'true' }} |
| 58 | + working-directory: packages/extester |
| 59 | + run: | |
| 60 | + PKG_VERSION=$(node -p "require('./package.json').version") |
| 61 | + TAG_VERSION=${VERSION} |
| 62 | + echo "Package version: $PKG_VERSION" |
| 63 | + echo "Input tag version: $TAG_VERSION" |
| 64 | + if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then |
| 65 | + echo "❌ Tag version ($TAG_VERSION) does not match package.json version ($PKG_VERSION)!" |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: 🔸 Get vscode-extension-tester version |
| 70 | + working-directory: packages/extester |
| 71 | + run: | |
| 72 | + VERSION=$(node -p "require('./package.json').version") |
| 73 | + echo "EXTESTER_VERSION=${VERSION}" >> $GITHUB_ENV |
| 74 | +
|
| 75 | + - name: 🔸 Get @redhat-developer/page-objects version |
| 76 | + working-directory: packages/page-objects |
| 77 | + run: | |
| 78 | + VERSION=$(node -p "require('./package.json').version") |
| 79 | + echo "PAGE_OBJECTS_VERSION=${VERSION}" >> $GITHUB_ENV |
| 80 | +
|
| 81 | + - name: 🔸 Get @redhat-developer/locators version |
| 82 | + working-directory: packages/locators |
| 83 | + run: | |
| 84 | + VERSION=$(node -p "require('./package.json').version") |
| 85 | + echo "LOCATORS_VERSION=${VERSION}" >> $GITHUB_ENV |
| 86 | +
|
| 87 | + - name: ⚙️ Set up Node.js |
| 88 | + uses: actions/setup-node@v4 |
| 89 | + with: |
| 90 | + node-version: 20 |
| 91 | + |
| 92 | + - name: 📦 Install GitHub CLI |
| 93 | + run: sudo apt-get install -y gh |
| 94 | + |
| 95 | + - name: 🔧 Install deps and build |
| 96 | + run: | |
| 97 | + npm ci |
| 98 | + npm run build |
| 99 | +
|
| 100 | + - name: 📝 Generate changelog |
| 101 | + run: | |
| 102 | + PREV_TAG=$(git tag --list "v*" --sort=-creatordate | grep -v "$TAG" | head -n 1) |
| 103 | + echo "Comparing changes from $PREV_TAG to $TAG" |
| 104 | +
|
| 105 | + if [ -z "$PREV_TAG" ]; then |
| 106 | + LOG=$(git log "$TAG" --reverse --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)") |
| 107 | + [ -z "$LOG" ] && LOG=$(git log --reverse --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)") |
| 108 | + else |
| 109 | + LOG=$(git log "$PREV_TAG..$TAG" --pretty='format:%s by **%aN** in %H' -- . | grep -vE "(runner)") |
| 110 | + fi |
| 111 | +
|
| 112 | + if [ -z "$LOG" ]; then |
| 113 | + LOG="Initial release (first tag)" |
| 114 | + fi |
| 115 | +
|
| 116 | + # Helper to format sections |
| 117 | + format_section() { |
| 118 | + local pattern="$1" |
| 119 | + local title="$2" |
| 120 | + local content=$(echo "$LOG" | grep -iE "$pattern" || true) |
| 121 | + if [[ -n "$content" ]]; then |
| 122 | + echo "### $title" |
| 123 | + echo "$content" |
| 124 | + echo |
| 125 | + fi |
| 126 | + } |
| 127 | +
|
| 128 | + format_other_section() { |
| 129 | + local title="🧼 Other Changes" |
| 130 | + local content=$(echo "$LOG" | grep -vE "^(feat|feature|fix|test|chore|refactor|internal|ci|docs|deps|dependencies|build)" || true) |
| 131 | + if [[ -n "$content" ]]; then |
| 132 | + echo "### $title" |
| 133 | + echo "$content" |
| 134 | + echo |
| 135 | + fi |
| 136 | + } |
| 137 | +
|
| 138 | + { |
| 139 | + echo "## What's Changed" |
| 140 | + format_section '^break|^breaking' "⚠️ Breaking" |
| 141 | + format_section '^feat|^feature' "🚀 Features" |
| 142 | + format_section '^fix' "🚫 Bugs" |
| 143 | + format_section '^test' "🔎 Tests" |
| 144 | + format_section '^chore|^refactor|^internal|^ci|^docs' "🔧 Maintenance" |
| 145 | + format_section '^deps|^dependencies|^build' "📦 Dependencies" |
| 146 | + format_other_section |
| 147 | + } > CHANGELOG.md |
| 148 | +
|
| 149 | + echo "Generated CHANGELOG.md" |
| 150 | + cat CHANGELOG.md |
| 151 | +
|
| 152 | + - name: 🚀 Publish to NPM registry (npmjs) |
| 153 | + if: ${{ github.event.inputs.skipPublish != 'true' }} |
| 154 | + run: npm run publish -- --yes |
| 155 | + env: |
| 156 | + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} |
| 157 | + |
| 158 | + - name: 📣 Add summary |
| 159 | + if: ${{ github.event.inputs.skipPublish != 'true' }} |
| 160 | + run: | |
| 161 | + echo "#### ✅ Published \`vscode-extension-tester-${EXTESTER_VERSION}\`" >> $GITHUB_STEP_SUMMARY |
| 162 | + echo "#### ✅ Published \`@redhat-developer/page-objects-${PAGE_OBJECTS_VERSION}\`" >> $GITHUB_STEP_SUMMARY |
| 163 | + echo "#### ✅ Published \`@redhat-developer/locators-${LOCATORS_VERSION}\`" >> $GITHUB_STEP_SUMMARY |
| 164 | +
|
| 165 | + - name: 🚀 Publish GitHub Release |
| 166 | + env: |
| 167 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 168 | + run: | |
| 169 | + if [ "${{ github.event.inputs.draft }}" == "true" ]; then |
| 170 | + echo "Publishing release as draft..." |
| 171 | + gh release create "$TAG" --title "v${VERSION}" --notes-file CHANGELOG.md --draft |
| 172 | + else |
| 173 | + echo "Publishing release as a regular release..." |
| 174 | + gh release create "$TAG" --title "v${VERSION}" --notes-file CHANGELOG.md |
| 175 | + fi |
0 commit comments