Skip to content

Commit

Permalink
ci: create publish release workflow (#9150)
Browse files Browse the repository at this point in the history
* ci: create publish release workflow

* test: fix tests for formatTag

* ci(publish-release): fix string concat

* ci: release action runs with tag as source

* ci(publish-release): no longer testing

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
ckohen and kodiakhq[bot] committed Feb 21, 2023
1 parent fd0246c commit 6e481f0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Publish Release
on:
release:
types: [released]
jobs:
npm-publish:
name: npm publish
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
if: github.repository_owner == 'discordjs'
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Install node.js v16
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/

- name: Install dependencies
uses: ./packages/actions/src/yarnCache

- name: Build dependencies
run: yarn build

- name: Extract package and semver from tag
id: extract-tag
uses: ./packages/actions/src/formatTag
with:
tag: ${{ github.ref_name }}

- name: Publish package
run: |
yarn workspace ${{ steps.extract-tag.outputs.subpackage == 'true' && '@discordjs/' || '' }}${{ steps.extract-tag.outputs.package }} npm publish
env:
YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
22 changes: 15 additions & 7 deletions packages/actions/__tests__/formatTag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import { formatTag } from '../src/index.js';

describe('Format Tag', () => {
test('GIVEN tag with a prefix THEN format tag to not contain the prefix', () => {
expect(formatTag('@discordjs/rest@0.4.0')).toEqual({ package: 'rest', semver: '0.4.0' });
expect(formatTag('@discordjs/collection@0.6.0')).toEqual({ package: 'collection', semver: '0.6.0' });
expect(formatTag('@discordjs/proxy@0.1.0')).toEqual({ package: 'proxy', semver: '0.1.0' });
expect(formatTag('@discordjs/builders@0.13.0')).toEqual({ package: 'builders', semver: '0.13.0' });
expect(formatTag('@discordjs/voice@0.9.0')).toEqual({ package: 'voice', semver: '0.9.0' });
expect(formatTag('@discordjs/rest@0.4.0')).toEqual({ isSubpackage: true, package: 'rest', semver: '0.4.0' });
expect(formatTag('@discordjs/collection@0.6.0')).toEqual({
isSubpackage: true,
package: 'collection',
semver: '0.6.0',
});
expect(formatTag('@discordjs/proxy@0.1.0')).toEqual({ isSubpackage: true, package: 'proxy', semver: '0.1.0' });
expect(formatTag('@discordjs/builders@0.13.0')).toEqual({
isSubpackage: true,
package: 'builders',
semver: '0.13.0',
});
expect(formatTag('@discordjs/voice@0.9.0')).toEqual({ isSubpackage: true, package: 'voice', semver: '0.9.0' });
});

test('GIVEN tag with no prefix THEN return tag', () => {
expect(formatTag('13.5.1')).toEqual({ package: 'discord.js', semver: '13.5.1' });
expect(formatTag('13.7.0')).toEqual({ package: 'discord.js', semver: '13.7.0' });
expect(formatTag('13.5.1')).toEqual({ isSubpackage: false, package: 'discord.js', semver: '13.5.1' });
expect(formatTag('13.7.0')).toEqual({ isSubpackage: false, package: 'discord.js', semver: '13.7.0' });
});

test('GIVEN no or invalid tag THEN return null', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/actions/src/formatTag/formatTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export function formatTag(tag: string) {

if (parsed?.groups) {
return {
isSubpackage: typeof parsed.groups.package === 'string',
package: parsed.groups.package ?? 'discord.js',
semver: parsed.groups.semver,
};
Expand Down
1 change: 1 addition & 0 deletions packages/actions/src/formatTag/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const tag = getInput('tag', { required: true });
const parsed = formatTag(tag);

if (parsed) {
setOutput('subpackage', parsed.isSubpackage);
setOutput('package', parsed.package);
setOutput('semver', parsed.semver);
}

2 comments on commit 6e481f0

@vercel
Copy link

@vercel vercel bot commented on 6e481f0 Feb 21, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 6e481f0 Feb 21, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.