diff --git a/.github/actions/bump-version/action.yml b/.github/actions/bump-version/action.yml deleted file mode 100644 index fbe69c8..0000000 --- a/.github/actions/bump-version/action.yml +++ /dev/null @@ -1,56 +0,0 @@ -name: Publish Experimental Packages -description: Bumps the version of an npm package and publishes it with an experimental tag. - -on: - workflow_call: [] - -inputs: - package_dir: - description: Directory of the Package to Publish - required: true - default: './' - -outputs: - VERSION_TAG: - description: Generated Experimental Version Tag for This Package - value: ${{ steps.version-tag.outputs.VERSION_TAG }} - -runs: - using: composite - steps: - - name: Construct Experimental Version Tag - id: version-tag - shell: bash - run: | - BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | sed -r 's/([a-z0-9])([A-Z])/\1-\L\2/g' | sed 's/_/-/g' | sed 's/\//-/g') - - echo "VERSION_TAG=$(echo $BRANCH_NAME)-experimental" >> $GITHUB_ENV - echo "VERSION_TAG=$(echo $VERSION_TAG)" >> $GITHUB_OUTPUT - - - name: Bump ${{ inputs.package_dir }} - shell: bash - run: | - cd ${{ inputs.package_dir }} - - PACKAGE_NAME=$(cat package.json | grep "name" | cut -d':' -f 2 | cut -d'"' -f 2) - echo "PACKAGE_NAME=${PACKAGE_NAME}" >> $GITHUB_ENV - - # Matches any version that ends with "-author-ron-123-experimental.". e.g. 1.0.0-leo-ron-123-experimental.0 - REGEX="\-$VERSION_TAG.[0-9]\{1,\}$" - - # Get all versions - ALL_VERSIONS=$(npm view $PACKAGE_NAME versions --json | jq -r '. | if type=="array" then .[] else . end') - - # Check if the experimental version already exists - if ! echo "$ALL_VERSIONS" | grep -q "$REGEX"; then - # If not, create it - npm version prerelease --preid=$VERSION_TAG --no-git-tag-version - else - # Otherwise up it - LATEST_VERSION=$(echo "$ALL_VERSIONS" | grep "$REGEX" | tail -1) - npm version $(npx semver $LATEST_VERSION -i prerelease --preid="$VERSION_TAG") --no-git-tag-version - fi - - - name: Publish to npm - shell: bash - run: cd ${{ inputs.package_dir }} && npm publish --tag="$VERSION_TAG" \ No newline at end of file diff --git a/.github/workflows/publish-experimental.yml b/.github/workflows/publish-experimental.yml index da7dd38..cd0a7e5 100644 --- a/.github/workflows/publish-experimental.yml +++ b/.github/workflows/publish-experimental.yml @@ -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/checkout@v3.1.0 - - # Needed only for bumping package version and publishing npm packages. - - name: Set up Node.js - uses: actions/setup-node@v3.5.1 - - 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. \ No newline at end of file +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 }} \ No newline at end of file diff --git a/.github/workflows/publish-manually.yml b/.github/workflows/publish-manually.yml index 46c0763..50bbd49 100644 --- a/.github/workflows/publish-manually.yml +++ b/.github/workflows/publish-manually.yml @@ -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 @@ -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/checkout@v3.1.0 - with: - token: ${{ steps.generate_token.outputs.token }} - - # Needed only for bumping package version and publishing npm packages. - - name: Set up Node.js - uses: actions/setup-node@v3.5.1 - - 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 \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/.github/workflows/remove-experimental.yml b/.github/workflows/remove-experimental.yml index 633a865..741dd82 100644 --- a/.github/workflows/remove-experimental.yml +++ b/.github/workflows/remove-experimental.yml @@ -7,70 +7,10 @@ on: types: [closed] jobs: - deploy: - runs-on: ubuntu-latest - name: Remove Experimental Packages - steps: - - name: Code Checkout - uses: actions/checkout@v3.1.0 - - - name: Set up Node.js - uses: actions/setup-node@v3.5.1 - - 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<> $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 \ No newline at end of file + 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 }} \ No newline at end of file diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 08b6022..01c2c5c 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -9,38 +9,7 @@ on: - main jobs: - lint: - name: Linting - runs-on: ubuntu-latest - steps: - - name: Code Checkout - uses: actions/checkout@v3.1.0 - - - 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/checkout@v3.1.0 - - - 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 \ No newline at end of file + validate: + uses: ronin-co/github-actions/.github/workflows/validate.yml@main + with: + package_dir: './' # Adjust if your package is in a subdirectory \ No newline at end of file