Skip to content

Commit

Permalink
ci: release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jul 1, 2024
1 parent cddfde9 commit df1bca6
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 115 deletions.
24 changes: 24 additions & 0 deletions .github/actions/resolve-release-version/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Resolve version
description: Read "version" of "@tutorialkit/astro" to "steps.resolve-release-version.outputs.version"

outputs:
version:
description: 'Version of @tutorialkit/astro'
value: ${{ steps.resolve-release-version.outputs.version }}

runs:
using: composite

steps:
- name: Resolve release version
id: resolve-release-version
shell: bash
run: >
echo "$(
node -e "
const fs = require('fs');
const pkg = fs.readFileSync('./packages/astro/package.json', 'utf8');
const version = JSON.parse(pkg).version
console.log('version=' + version);
"
)" >> $GITHUB_OUTPUT
26 changes: 26 additions & 0 deletions .github/workflows/integration-test-cli.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Integration Tests CLI

on:
pull_request:

jobs:
cli-integration-test:
name: CLI Integration Tests
# Note: `prepare-release.yaml` sets this commit message
if: ${{ contains(github.event.pull_request.title, 'release tutorialkit CLI') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build

- name: Update template's versions
working-directory: ./packages/cli
run: pnpm update-template

- name: Integration Tests
working-directory: ./integration
run: pnpm test
44 changes: 44 additions & 0 deletions .github/workflows/prepare-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Prepare release PR

on:
workflow_dispatch:
inputs:
version:
description: 'Version to publish, e.g. 0.0.1'
required: true
default: '0.0.1'
type: string

jobs:
prepare_release:
name: Prepare release PR
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build

- name: Bump versions
run: >
pnpm --recursive
--filter "@tutorialkit/*"
--filter create-tutorial
exec pnpm version --no-git-tag-version --allow-same-version ${{ inputs.version }}
- name: Generage changelog
run: |
pnpm run changelog
git checkout ./packages/cli
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
# Note: `publish-release.yaml` checks explicitly for this commit message
commit-message: 'chore: release @tutorialkit packages and create-tutorial, version: ${{ inputs.version }}'
title: 'chore: release @tutorialkit packages and create-tutorial, version: ${{ inputs.version }}'
body: 'Bump packages to version ${{ inputs.version }} and generate changelogs'
reviewers: SamVerschueren,d3lm,Nemikolh,AriPerkkio
branch: chore/release-${{ inputs.version }}
111 changes: 111 additions & 0 deletions .github/workflows/publish-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Publish release

on:
push:
branches:
- main

jobs:
publish_release:
name: Publish release
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
# Note: `prepare-release.yaml` sets this commit message
if: ${{ contains(github.event.head_commit.message, 'release @tutorialkit packages') }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build

# Sets steps.resolve-release-version.outputs.version
- uses: ./.github/actions/resolve-release-version
id: resolve-release-version

- name: Publish to npm
run: >
pnpm --recursive
--filter "@tutorialkit/*"
--filter create-tutorial
exec pnpm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Create and push git tag
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git tag v${{ steps.resolve-release-version.outputs.version }}
git push origin v${{ steps.resolve-release-version.outputs.version }}
prepare_cli_release:
name: Prepare release for CLI
needs: [publish_release]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build

# Sets steps.resolve-release-version.outputs.version
- uses: ./.github/actions/resolve-release-version
id: resolve-release-version

- name: Bump version
run: >
pnpm --recursive
--filter tutorialkit
exec npm version --no-git-tag-version --allow-same-version ${{ steps.resolve-release-version.outputs.version }}
- name: Generage changelog
run: |
pnpm run changelog
git add ./packages/cli ./packages/template
git checkout ./packages
git checkout CHANGELOG.md
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
# Note: `publish-release.yaml` checks explicitly for this commit message
commit-message: 'chore: release tutorialkit CLI, version: ${{ steps.resolve-release-version.outputs.version }}'
title: 'chore: release tutorialkit CLI, version: ${{ steps.resolve-release-version.outputs.version }}'
body: 'Bump tutorialkit CLI to version ${{ steps.resolve-release-version.outputs.version }} and generate changelog'
reviewers: SamVerschueren,d3lm,Nemikolh,AriPerkkio
branch: chore/release-cli-${{ steps.resolve-release-version.outputs.version }}

publish_release_CLI:
name: Publish release CLI
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
# Note: `prepare-release.yaml` sets this commit message
if: ${{ contains(github.event.head_commit.message, 'release tutorialkit CLI') }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ./.github/actions/setup-and-build

- name: Update template's versions
working-directory: ./packages/cli
run: pnpm update-template

- name: Integration Tests
working-directory: ./integration
run: pnpm test

- name: Publish to npm
run: pnpm --recursive --filter tutorialkit exec pnpm publish --provenance
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
36 changes: 0 additions & 36 deletions .github/workflows/publish.yaml

This file was deleted.

57 changes: 57 additions & 0 deletions integration/cli/__snapshots__/create-tutorial.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ exports[`npm > should create a project 1`] = `
"icons/languages/ts.svg",
"package-lock.json",
"package.json",
"pnpm-lock.yaml",
"public",
"public/favicon.svg",
"public/logo-dark.svg",
"public/logo.svg",
"src",
"src/content",
Expand Down Expand Up @@ -53,6 +55,23 @@ exports[`npm > should create a project 1`] = `
"src/templates/default/style.css",
"tsconfig.json",
"uno.config.ts",
"yarn.lock",
]
`;

exports[`npm > should create and build a project 1`] = `
[
"1-basics",
"1-basics-1-introduction-1-welcome-files.json",
"1-basics-1-introduction-1-welcome-solution.json",
"1-basics/1-introduction",
"1-basics/1-introduction/1-welcome",
"1-basics/1-introduction/1-welcome/index.html",
"favicon.svg",
"index.html",
"logo-dark.svg",
"logo.svg",
"template-default.json",
]
`;

Expand All @@ -74,10 +93,12 @@ exports[`pnpm > should create a project 1`] = `
"icons/languages/markdown.svg",
"icons/languages/sass.svg",
"icons/languages/ts.svg",
"package-lock.json",
"package.json",
"pnpm-lock.yaml",
"public",
"public/favicon.svg",
"public/logo-dark.svg",
"public/logo.svg",
"src",
"src/content",
Expand Down Expand Up @@ -109,6 +130,23 @@ exports[`pnpm > should create a project 1`] = `
"src/templates/default/style.css",
"tsconfig.json",
"uno.config.ts",
"yarn.lock",
]
`;

exports[`pnpm > should create and build a project 1`] = `
[
"1-basics",
"1-basics-1-introduction-1-welcome-files.json",
"1-basics-1-introduction-1-welcome-solution.json",
"1-basics/1-introduction",
"1-basics/1-introduction/1-welcome",
"1-basics/1-introduction/1-welcome/index.html",
"favicon.svg",
"index.html",
"logo-dark.svg",
"logo.svg",
"template-default.json",
]
`;

Expand All @@ -130,9 +168,12 @@ exports[`yarn > should create a project 1`] = `
"icons/languages/markdown.svg",
"icons/languages/sass.svg",
"icons/languages/ts.svg",
"package-lock.json",
"package.json",
"pnpm-lock.yaml",
"public",
"public/favicon.svg",
"public/logo-dark.svg",
"public/logo.svg",
"src",
"src/content",
Expand Down Expand Up @@ -167,3 +208,19 @@ exports[`yarn > should create a project 1`] = `
"yarn.lock",
]
`;

exports[`yarn > should create and build a project 1`] = `
[
"1-basics",
"1-basics-1-introduction-1-welcome-files.json",
"1-basics-1-introduction-1-welcome-solution.json",
"1-basics/1-introduction",
"1-basics/1-introduction/1-welcome",
"1-basics/1-introduction/1-welcome/index.html",
"favicon.svg",
"index.html",
"logo-dark.svg",
"logo.svg",
"template-default.json",
]
`;
31 changes: 15 additions & 16 deletions integration/cli/create-tutorial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,21 @@ describe('yarn', () => {
});

async function createProject(name: string, packageManager: string, options: { cwd: string; install?: boolean }) {
await execa(
'node',
[
cli,
'create',
name,
`--${options.install ? '' : 'no-'}install`,
'--no-git',
'--package-manager',
packageManager,
'--defaults',
],
{
cwd: options.cwd,
},
);
const args = [
cli,
'create',
name,
`--${options.install ? '' : 'no-'}install`,
'--no-git',
'--no-start',
'--package-manager',
packageManager,
'--defaults',
];

console.log(`> node ${args.join(' ')}`);

await execa('node', args, { cwd: options.cwd });
}

function normaliseSlash(filePath: string) {
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"scripts": {
"build": "node scripts/build.js",
"prepack": "node scripts/pre-pack.js",
"postpack": "node scripts/cleanup.js"
"update-template": "node scripts/update-template.js"
},
"files": [
"dist",
Expand Down
Loading

0 comments on commit df1bca6

Please sign in to comment.