Skip to content

Commit

Permalink
ci: improve workflows and Docker image (#314)
Browse files Browse the repository at this point in the history
* ci: improve workflows and Docker image
* chore: add vscode devcontainer
  • Loading branch information
peaceiris authored Nov 23, 2020
1 parent 29ce8d9 commit c81148b
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 60 deletions.
35 changes: 35 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "Node.js",
"image": "docker.pkg.github.com/peaceiris/actions-label-commenter/alc-dev:latest",

// Use 'settings' to set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
},

// Add the IDs of extensions you want installed when the container is created in the array below.
"extensions": [
"bungcip.better-toml",
"EditorConfig.EditorConfig",
"donjayamanne.githistory",
"eamodio.gitlens",
"oderwat.indent-rainbow",
"yzhang.markdown-all-in-one",
"shd101wyy.markdown-preview-enhanced",
"christian-kohler.path-intellisense",
"lfs.vscode-emacs-friendly",
"ms-azuretools.vscode-docker",
"dbaeumer.vscode-eslint",
"firsttris.vscode-jest-runner",
"VisualStudioExptTeam.vscodeintellicode"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [3000],

// Specifies a command that should be run after the container has been created.
"postCreateCommand": "npm ci",

// Comment out the next line to run as root instead.
// "remoteUser": "runner"
}
5 changes: 0 additions & 5 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2

- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/dev-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'Dev Image CI'

on:
workflow_dispatch:
schedule:
- cron: '11 11 * * *'
push:
branches:
- main
paths:
- '.github/workflows/dev-image.yml'
- '.dockerignore'
- '.nvmrc'
- 'Dockerfile'
- 'Makefile'
- 'docker-compose.yml'
pull_request:
paths:
- '.github/workflows/dev-image.yml'
- '.dockerignore'
- '.nvmrc'
- 'Dockerfile'
- 'Makefile'
- 'docker-compose.yml'

jobs:
skipci:
runs-on: ubuntu-18.04
steps:
- run: echo "[skip ci] ${{ contains(github.event.head_commit.message, '[skip ci]') }}"

dev-image-test:
runs-on: ubuntu-18.04
if: contains(github.event.head_commit.message, '[skip ci]') == false
steps:
- uses: actions/checkout@v2
- name: Login to Packages
run: echo '${{ secrets.GITHUB_TOKEN }}' | docker login 'docker.pkg.github.com' -u 'peaceiris' --password-stdin
- run: docker-compose pull --quiet
if: github.event_name == 'pull_request'
- run: make build
- run: docker images
- run: make ci
- run: make all
- run: docker-compose push
if: github.ref == 'refs/heads/main'
23 changes: 1 addition & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,6 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "${GITHUB_CONTEXT}"

- name: Install github/hub
run: |
export HUB_VERSION="2.14.2"
curl -fsSL https://github.com/github/hub/raw/8d91904208171b013f9a9d1175f4ab39068db047/script/get | bash -s "${HUB_VERSION}"
- name: Create release
- uses: peaceiris/workflows/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${GITHUB_REF##refs/tags/}"
echo "See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/${TAG_NAME}/CHANGELOG.md) for more details." > ./release_notes.md
RELEASE_NAME="$(jq -r '.name' ./package.json)"
sed -i "1i${RELEASE_NAME} ${TAG_NAME}\n" ./release_notes.md
./bin/hub release create \
--draft \
--prerelease \
--file ./release_notes.md \
"${TAG_NAME}"
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
npm --version
git --version
- run: npm ci
- run: npm run format:check
- run: npm run fmt:check
- run: npm run lint
- run: npm run build
- run: npm test
Expand All @@ -52,5 +52,3 @@ jobs:
path: coverage

# - uses: codecov/codecov-action@v1
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
42 changes: 26 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,37 @@ FROM node:${NODE_VERSION}-buster-slim

SHELL ["/bin/bash", "-l", "-c"]

ENV DEBIAN_FRONTEND="noninteractive"
ENV NODE_ENV="development"

RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf \
ca-certificates \
wget \
vim && \
vim \
git && \
apt-get autoclean && \
apt-get clean && \
apt-get autoremove -y && \
rm -rf /var/lib/apt/lists/* && \
npm i -g npm

WORKDIR /git
ENV GIT_VERSION="2.25.1"
RUN wget -q "https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz" && \
tar -zxf "./v${GIT_VERSION}.tar.gz" && \
rm "./v${GIT_VERSION}.tar.gz" && \
cd "./git-${GIT_VERSION}" && \
make configure && \
./configure --prefix=/usr && \
make all && \
make install
npm i -g npm && \
npm cache clean --force

WORKDIR /repo

ENV LANG="C.UTF-8"
ENV CI="true"
ENV ImageVersion="20200717.1"
ENV GITHUB_SERVER_URL="https://github.com"
ENV GITHUB_API_URL="https://api.github.com"
ENV GITHUB_GRAPHQL_URL="https://api.github.com/graphql"
ENV GITHUB_REPOSITORY_OWNER="peaceiris"
ENV GITHUB_ACTIONS="true"
ENV GITHUB_ACTOR="peaceiris"
ENV GITHUB_REPOSITORY="actions/pages"
ENV RUNNER_OS="Linux"
ENV RUNNER_TOOL_CACHE="/opt/hostedtoolcache"
ENV RUNNER_USER="runner"
ENV RUNNER_TEMP="/home/runner/work/_temp"
ENV RUNNER_WORKSPACE="/home/runner/work/pages"

CMD [ "bash" ]
23 changes: 11 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
cmd := "bash"
msg := ""
IMAGE_NAME := actions_label_commenter_dev:latest
IMAGE_NAME := docker.pkg.github.com/peaceiris/actions-label-commenter/alc-dev:latest
NODE_VERSION := $(shell cat ./.nvmrc)
DOCKER_BUILD := docker build . -t $(IMAGE_NAME) --build-arg NODE_VERSION=$(NODE_VERSION)
DOCKER_RUN := docker run --rm -i -t -v ${PWD}:/repo -v ~/.gitconfig:/root/.gitconfig $(IMAGE_NAME)


.PHONY: build
build:
$(DOCKER_BUILD)
docker-compose build --build-arg NODE_VERSION=$(NODE_VERSION)

.PHONY: run
run:
$(DOCKER_RUN) $(cmd)
docker-compose run --rm dev bash

.PHONY: ci
ci:
docker-compose run --rm -T dev npm ci

.PHONY: test
test:
$(DOCKER_RUN) npm test
docker-compose run --rm -T dev npm test

.PHONY: commit
commit:
$(DOCKER_RUN) git commit -m "$(msg)"
.PHONY: all
all:
docker-compose run --rm -T dev npm run all
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.2'

services:
dev:
image: 'docker.pkg.github.com/peaceiris/actions-label-commenter/alc-dev:latest'
build:
context: .
cache_from:
- 'docker.pkg.github.com/peaceiris/actions-label-commenter/alc-dev:latest'
container_name: peaceiris_actions_label_commenter
volumes:
- ${PWD}:/repo
stdin_open: true
tty: true
command:
- bash
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
"test": "jest --coverage --verbose",
"build": "ncc build ./src/index.ts -o lib --minify",
"tsc": "tsc",
"format": "prettier --write **/*.ts",
"format:check": "prettier --check **/*.ts",
"fmt": "prettier --write **/*.ts",
"fmt:check": "prettier --check **/*.ts",
"all": "npm run fmt && npm run lint && npm test",
"release": "standard-version",
"update-deps": "(git diff 'HEAD@{1}' --name-only | grep 'package-lock.json' > /dev/null) && npm ci || :"
},
Expand Down

0 comments on commit c81148b

Please sign in to comment.