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

Make use of reusable workflow #31

Merged
merged 7 commits into from
Nov 14, 2024
Merged
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
56 changes: 0 additions & 56 deletions .github/actions/bump-version/action.yml

This file was deleted.

52 changes: 10 additions & 42 deletions .github/workflows/publish-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,14 @@ on:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
permissions:
# Required for `actions/checkout@v3`
contents: read
# Required for `thollander/actions-comment-pull-request@v2`
pull-requests: write

steps:
- name: Code Checkout
uses: actions/[email protected]

# Needed only for bumping package version and publishing npm packages.
- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install Dependencies
run: bun install --frozen-lockfile
permissions:
pull-requests: write
contents: read

- name: Build Package
run: bun run build

- name: Bump Package
uses: ./.github/actions/bump-version

- name: Comment on PR
uses: thollander/actions-comment-pull-request@v2
with:
comment_tag: packages_announcement
message: |
Released an experimental package:

```bash
bun add @ronin/compiler@${{ env.VERSION_TAG }}
```

This package will be removed after the pull request has been merged.
jobs:
publish-experimental:
uses: ronin-co/github-actions/.github/workflows/publish-experimental.yml@main
with:
package_dir: './' # Adjust if your package is in a subdirectory
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_READ_AND_WRITE }}
65 changes: 10 additions & 55 deletions .github/workflows/publish-manually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version_type:
description: Choose a version type to bump the package version by.
description: 'Version type to bump the package version by.'
required: true
default: 'patch'
type: choice
Expand All @@ -15,57 +15,12 @@ on:
- prerelease

jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Generate GitHub App Token
id: generate_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.ORG_GH_RONIN_APP_ID }}
private_key: ${{ secrets.ORG_GH_RONIN_APP_PRIVATE_KEY }}

- name: Code Checkout
uses: actions/[email protected]
with:
token: ${{ steps.generate_token.outputs.token }}

# Needed only for bumping package version and publishing npm packages.
- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

- name: Set up Bun
uses: oven-sh/setup-bun@v1

- name: Install Dependencies
run: bun install --frozen-lockfile

- name: Build Package
run: bun run build

- name: Set Git Config
run: |
# See where these config values come from at https://stackoverflow.com/a/74071223
git config --global user.name "ronin-app[bot]"
git config --global user.email 135042755+ronin-app[bot]@users.noreply.github.com

- name: Bump Package
run: |
npm version ${{ inputs.version_type }} --git-tag-version=false
echo "NEW_VERSION=$(npm pkg get version --workspaces=false | tr -d \")" >> $GITHUB_ENV

- name: Push New Version
run: |
git fetch
git checkout ${GITHUB_HEAD_REF}
git pull origin ${GITHUB_HEAD_REF}
git commit -a -m '${{ env.NEW_VERSION }}' --no-verify
git tag -a ${{ env.NEW_VERSION }} -m '${{ env.NEW_VERSION }}'
git push origin ${GITHUB_HEAD_REF}
# Push tag
git push origin ${{ env.NEW_VERSION }}

- name: Publish npm Package
run: npm publish
publish:
uses: ronin-co/github-actions/.github/workflows/publish-manually.yml@main
with:
version_type: ${{ inputs.version_type }}
package_dir: './' # Adjust if your package is in a subdirectory
secrets:
NPM_TOKEN_READ_AND_WRITE: ${{ secrets.NPM_TOKEN_READ_AND_WRITE }}
ORG_GH_APP_ID: ${{ secrets.ORG_GH_RONIN_APP_ID }}
ORG_GH_APP_PRIVATE_KEY: ${{ secrets.ORG_GH_RONIN_APP_PRIVATE_KEY }}
74 changes: 7 additions & 67 deletions .github/workflows/remove-experimental.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,10 @@ on:
types: [closed]

jobs:
deploy:
runs-on: ubuntu-latest
name: Remove Experimental Packages
steps:
- name: Code Checkout
uses: actions/[email protected]

- name: Set up Node.js
uses: actions/[email protected]
- run: echo '//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN_READ_AND_WRITE }}' > ~/.npmrc

- name: Get Branch Name
id: get_branch_name
run: echo "branch_name=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT

- name: Get Versions to Unpublish
id: get_versions
run: |
PACKAGE_NAME="@ronin/compiler"
BRANCH_NAME="${{ steps.get_branch_name.outputs.branch_name }}"
echo "Original Branch Name: $BRANCH_NAME"

# Sanitize branch name by replacing slashes with hyphens
BRANCH_NAME_SANITIZED=$(echo "$BRANCH_NAME" | tr '/' '-')
echo "Sanitized Branch Name: $BRANCH_NAME_SANITIZED"

# Retrieve all versions
VERSIONS=$(npm view $PACKAGE_NAME versions --json)

# Check if VERSIONS is empty
if [ -z "$VERSIONS" ]; then
echo "No versions found for $PACKAGE_NAME."
exit 0
fi

# Filter versions that match the pattern
MATCHING_VERSIONS=$(echo "$VERSIONS" | tr -d '[]" ' | tr ',' '\n' | grep -F -- "-${BRANCH_NAME_SANITIZED}-experimental" || true)

# Check if any versions match
if [ -z "$MATCHING_VERSIONS" ]; then
echo "No versions to unpublish for branch $BRANCH_NAME."
exit 0
fi

# Output the versions to unpublish
echo "versions<<EOF" >> $GITHUB_OUTPUT
echo "$MATCHING_VERSIONS" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Unpublish Versions
if: ${{ steps.get_versions.outputs.versions != '' }}
run: |
PACKAGE_NAME="@ronin/compiler"

# Read versions into an array
mapfile -t versions_array <<< "${{ steps.get_versions.outputs.versions }}"

# Check if versions_array is not empty
if [ ${#versions_array[@]} -eq 0 ]; then
echo "No versions to unpublish."
exit 0
fi

for VERSION in "${versions_array[@]}"; do
echo "Unpublishing $PACKAGE_NAME@$VERSION"
npm unpublish "$PACKAGE_NAME@$VERSION" || echo "Failed to unpublish $PACKAGE_NAME@$VERSION"
done
remove-experimental:
uses: ronin-co/github-actions/.github/workflows/remove-experimental.yml@main
with:
branch_name: ${{ github.event.pull_request.head.ref }}
package_dir: './' # Adjust if your package is in a subdirectory
secrets:
NPM_TOKEN_READ_AND_WRITE: ${{ secrets.NPM_TOKEN_READ_AND_WRITE }}
39 changes: 4 additions & 35 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,7 @@ on:
- main

jobs:
lint:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/[email protected]

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.27

- name: Install Dependencies
run: bun install

- name: Lint
run: bun run lint

test:
name: Testing
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/[email protected]

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: 1.1.27

- name: Install Dependencies
run: bun install

- name: Test
run: bun test
validate:
uses: ronin-co/github-actions/.github/workflows/validate.yml@main
with:
package_dir: './' # Adjust if your package is in a subdirectory
Loading