Skip to content

Commit

Permalink
Switch from yarn to npm and refactor the action code (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarampampam authored Jun 20, 2024
1 parent 35669d9 commit 1bca4f1
Show file tree
Hide file tree
Showing 21 changed files with 1,471 additions and 2,996 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/main/schemas/devContainer.base.schema.json",
"name": "default",
"image": "node:20-bookworm",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/sshd:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"streetsidesoftware.code-spell-checker"
]
}
},
"postCreateCommand": "npm install"
}
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

[{*.yml,*.yaml}]
ij_any_spaces_within_braces = false
ij_any_spaces_within_brackets = false

[Makefile]
indent_style = tab
18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

3 changes: 2 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Docs: <https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/customizing-dependency-updates>
# yaml-language-server: $schema=https://json.schemastore.org/dependabot-2.0.json
# docs: https://docs.github.com/en/free-pro-team@latest/github/administering-a-repository/customizing-dependency-updates

version: 2

Expand Down
13 changes: 13 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-release-config.json
# docs: https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

changelog:
categories:
- title: 🛠 Fixes
labels: [type:fix, type:bug]
- title: 🚀 Features
labels: [type:feature, type:feature_request]
- title: 📦 Dependency updates
labels: [dependencies]
- title: Other Changes
labels: ['*']
9 changes: 6 additions & 3 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: dependabot
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions

name: 🤖 Dependabot

on:
pull_request: {}
Expand All @@ -9,15 +12,15 @@ permissions:

jobs:
dependabot: # https://tinyurl.com/e69djmen
name: Enable auto-merge for Dependabot PRs
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- uses: dependabot/fetch-metadata@v2
id: metadata
with: {github-token: "${{ secrets.GITHUB_TOKEN }}"}

- name: Enable auto-merge for Dependabot PRs
if: ${{ contains(fromJSON('["version-update:semver-minor", "version-update:semver-patch"]'), steps.metadata.outputs.update-type) }}
- if: ${{ contains(fromJSON('["version-update:semver-minor", "version-update:semver-patch"]'), steps.metadata.outputs.update-type) }}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: release
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions

name: 🚀 Release

on:
release: # Docs: <https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release>
Expand All @@ -10,12 +13,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: gacts/github-slug@v1
id: slug

- name: Setup git
env: {REPO_PATH: "${{ github.repository_owner }}/${{ github.event.repository.name }}"}
- {uses: gacts/github-slug@v1, id: slug}
- env: {REPO_PATH: "${{ github.repository_owner }}/${{ github.event.repository.name }}"}
run: |
git config --local user.email '[email protected]'
git config --local user.name "${{ github.actor }}"
Expand Down
63 changes: 17 additions & 46 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: tests
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
# docs: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions

name: 🧪 Tests

on:
push:
Expand All @@ -12,66 +15,37 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env: {FORCE_COLOR: 'true'}

jobs:
gitleaks:
name: GitLeaks
name: Check for GitLeaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: {fetch-depth: 0}

- name: Check for GitLeaks
uses: gacts/gitleaks@v1 # Action page: <https://github.com/gacts/gitleaks>
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1

eslint:
name: Run eslint
name: Run code linter
runs-on: ubuntu-latest
env: {FORCE_COLOR: 'true'}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with: {node-version: '20'}

- uses: actions/cache@v4
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-

- if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --no-progress --non-interactive

- run: yarn lint
- {uses: gacts/setup-node-with-cache@v1, with: {node-version: 20}}
- run: npm install
- run: npm run lint

dist-built:
name: Check distributive built state
runs-on: ubuntu-latest
outputs:
dist-changed: ${{ steps.state.outputs.changed }}
env: {FORCE_COLOR: 'true'}
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with: {node-version: '20'}

- uses: actions/cache@v4
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-

- if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile --no-progress --non-interactive

- run: yarn build

- {uses: gacts/setup-node-with-cache@v1, with: {node-version: 20}}
- run: npm install
- run: npm run build
- uses: actions/upload-artifact@v4
with: {name: dist, path: ./dist/, retention-days: 1}

- id: state
run: echo "changed=`git diff --diff-filter=ACMUXTR --name-only | grep dist/ > /dev/null && echo 'true' || echo 'false'`" >> $GITHUB_OUTPUT

Expand All @@ -85,13 +59,10 @@ jobs:
pull-requests: write
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with: {name: dist, path: ./dist/}

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Automatic distributive rebuild
with: {commit_message: Automatic distributive rebuild}

run-this-action:
name: Run action (${{ matrix.runs-on }})
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
# Environment files
*.env

# npm lock file (use yarn only)
package-lock.json
# yarn lock file (use npm only)
yarn.lock

# Logs
logs
*.log
yarn-debug.log*
yarn-error.log*

# Temp dirs & trash
/temp
Expand Down
26 changes: 0 additions & 26 deletions CHANGELOG.md

This file was deleted.

35 changes: 19 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
#!/usr/bin/make
# Makefile readme (ru): <https://blog.hook.sh/nix/makefile-full-doc/>
# Makefile readme (en): <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents>
# Makefile readme: <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents>

SHELL = /bin/bash
DC_RUN_ARGS = --rm --user "$(shell id -u):$(shell id -g)"
.DEFAULT_GOAL := build
.MAIN := build

.PHONY : help install shell lint test build
.DEFAULT_GOAL : help

help: ## Show this help
@printf "\033[33m%s:\033[0m\n" 'Available commands'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[32m%-18s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
NODE_IMAGE = node:20-alpine
RUN_ARGS = --rm -v "$(shell pwd):/src:rw" \
-t --workdir "/src" \
-u "$(shell id -u):$(shell id -g)" \
-e "NPM_CONFIG_UPDATE_NOTIFIER=false" \
-e PATH="$$PATH:/src/node_modules/.bin" $(NODE_IMAGE)

.PHONY: install
install: ## Install all dependencies
docker-compose run $(DC_RUN_ARGS) node yarn install --no-progress --non-interactive
docker run $(RUN_ARGS) npm install

.PHONY: shell
shell: ## Start shell into a container with node
docker-compose run $(DC_RUN_ARGS) node sh
docker run -e "PS1=\[\033[1;34m\]\w\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]" -i $(RUN_ARGS) sh

lint: ## Execute provided linters
docker-compose run $(DC_RUN_ARGS) node yarn lint
.PHONY: lint
lint: ## Run lint
docker run $(RUN_ARGS) npm run lint

build: ## Build frontend
docker-compose run $(DC_RUN_ARGS) node yarn build
.PHONY: build
build: install ## Build the extension and pack it into a zip file
docker run $(RUN_ARGS) npm run build
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[![Build Status][badge_build]][link_build]
[![License][badge_license]][link_license]

This action checks if the user is a stargazer (starred a repo or not). It can be run on **Linux** (`ubuntu-latest`), **Windows** (`windows-latest`) or **macOS** (`macos-latest`).
This action checks if the user is a stargazer (starred a repo or not). It can be run on **Linux** (`ubuntu-latest`),
**Windows** (`windows-latest`) or **macOS** (`macos-latest`).

## Usage

Expand All @@ -25,7 +26,7 @@ jobs:
# repository: ${{ github.repository }}

- if: steps.check-star.outputs.is-stargazer != 'true'
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: core.setFailed('⭐ Please, star this repository!')
```
Expand All @@ -45,7 +46,7 @@ jobs:
id: check-star
- if: steps.check-star.outputs.is-stargazer != 'true'
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
Expand All @@ -60,7 +61,7 @@ jobs:

### Inputs

Following inputs can be used as `step.with` keys:
The following inputs can be used as `step.with` keys:

| Name | Type | Default | Required | Description |
|----------------|:--------:|:--------------------------:|:--------:|-----------------------------------------------|
Expand All @@ -76,25 +77,24 @@ Following inputs can be used as `step.with` keys:

## Releasing

New versions releasing scenario:
To release a new version:

- Make required changes in the [changelog](CHANGELOG.md) file
- Build the action distribution (`make build` or `yarn build`)
- Commit and push changes (including `dist` directory changes - this is important) into the `master` branch
- Publish new release using repo releases page (git tag should follow `vX.Y.Z` format)
- Build the action distribution (`make build` or `npm run build`).
- Commit and push changes (including `dist` directory changes - this is important) to the `master|main` branch.
- Publish the new release using the repo releases page (the git tag should follow the `vX.Y.Z` format).

Major and minor git tags (`v1` and `v1.2` if you publish `v1.2.Z` release) will be updated automatically.
Major and minor git tags (`v1` and `v1.2` if you publish a `v1.2.Z` release) will be updated automatically.

## Support

[![Issues][badge_issues]][link_issues]
[![Issues][badge_pulls]][link_pulls]
[![Pull Requests][badge_pulls]][link_pulls]

If you find any action errors, please, [make an issue][link_create_issue] in the current repository.
If you find any errors in the action, please [create an issue][link_create_issue] in this repository.

## License

This is open-sourced software licensed under the [MIT License][link_license].
This is open-source software licensed under the [MIT License][link_license].

[badge_build]:https://img.shields.io/github/actions/workflow/status/gacts/is-stargazer/tests.yml?branch=master&maxAge=30
[badge_release_version]:https://img.shields.io/github/release/gacts/is-stargazer.svg?maxAge=30
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-action.json
# docs: https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions

name: Is the user stargazer?
description: Checks if the user is a stargazer (starred a repo or not)

Expand Down
5 changes: 2 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

1 change: 0 additions & 1 deletion dist/sourcemap-register.js

This file was deleted.

Loading

0 comments on commit 1bca4f1

Please sign in to comment.