Skip to content

Commit

Permalink
chore: Make Create Release action (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmandM authored May 15, 2024
1 parent cb57cca commit e52676e
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 39 deletions.
47 changes: 8 additions & 39 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,21 @@ on:
- released # prd

jobs:
verify:
setup:
runs-on: ubuntu-latest
outputs:
do_dry_run: ${{ steps.variables.outputs.is_dry_run }}
environment: ${{ steps.variables.outputs.env }}
npm_package_version: ${{ steps.set_version.outputs.version }}
npm_package_version: ${{ steps.variables.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm test
- id: variables
run: |
echo "env=dry-run" >> $GITHUB_OUTPUT
echo "is_dry_run=--dry-run" >> $GITHUB_OUTPUT
echo "current_version=$(npm show ts-mock-imports version)" >> $GITHUB_OUTPUT
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "env=production" >> $GITHUB_OUTPUT
echo "is_dry_run=" >> $GITHUB_OUTPUT
fi
- id: semver
uses: matt-usurp/validate-semver@v2
with:
version: ${{ github.event.release.tag_name }}
- id: set_version
run: echo "version=${{ steps.semver.outputs.version }}" >> $GITHUB_OUTPUT
- run: echo "Creating release for ts-mock-imports at version ${{ steps.semver.outputs.version }} with ${{ steps.variables.outputs.is_dry_run }}. Current version is ${{ steps.variables.outputs.current_version }}."

update_version:
runs-on: ubuntu-latest
needs: verify
environment: ${{ needs.verify.outputs.environment }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: |
date > generated.txt
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
npm version ${{ needs.verify.outputs.npm_package_version }}
git push && git push --tags
run: echo "version=$(npm show ts-mock-imports version)" >> $GITHUB_OUTPUT
- run: echo "Creating release for ts-mock-imports at version ${{ steps.variables.outputs.version }}"

publish-npm:
needs: [verify, update_version]
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -67,7 +36,7 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.PUBLISH_NPM_TOKEN }}

publish-gpr:
needs: [verify, update_version]
needs: setup
runs-on: ubuntu-latest
steps:
- run: echo ${{ needs.verify.outputs.do_dry_run }}
Expand All @@ -92,7 +61,7 @@ jobs:

external_test:
runs-on: ubuntu-latest
needs: [verify, publish-npm]
needs: [setup, publish-npm]
steps:
- uses: actions/setup-node@v4
- uses: actions/checkout@v4
Expand All @@ -101,5 +70,5 @@ jobs:

- run: npm ci
- run: npm uninstall ts-mock-imports # Ensure no contamination from existing version
- run: npm install ts-mock-imports@${{ needs.verify.outputs.npm_package_version }}
- run: npm install ts-mock-imports@${{ needs.setup.outputs.npm_package_version }}
- run: npm test
62 changes: 62 additions & 0 deletions .github/workflows/update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Setup Release
on:
workflow_dispatch:
inputs:
semver_type:
description: "What semver type is this release?"
type: choice
required: true
options:
- patch
- minor
prerelease:
description: "Pre Release"
type: boolean
required: false

jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: npm ci
- run: npm run build
- run: npm run lint
- run: npm test
- id: update_version
run: |
date > generated.txt
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
cmd=( npm version )
if [[ ${{ inputs.prerelease }} ]]; then
cmd+=( --preid=pre pre${{ inputs.semver_type }} )
else
cmd+=( ${{ inputs.semver_type }} )
fi
echo "Running ${cmd[@]}"
git push && git push --tags
- id: new_version
run: |
version=$(npm show ts-mock-imports version)
if [[ ${{ inputs.prerelease }} ]]; then
version+="-${{ github.sha }}"
fi
echo "version_number=$version" >> $GITHUB_OUTPUT
- id: pack_tar
run: |
npm run build
echo "tar_name=$(npm pack)" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
artifacts: "${{ steps.pack_tar.outputs.tar_name }}"
tag: "v${{ steps.new_version.outputs.version_number }}"
commit: "Release version v${{ steps.new_version.outputs.version_number }}"
generateReleaseNotes: true
prerelease: ${{ inputs.prerelease }}

0 comments on commit e52676e

Please sign in to comment.