This repository has been archived by the owner on Apr 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,19 @@ on: | |
- closed | ||
|
||
env: | ||
# イメージをアップロードするレジストリ | ||
REGISTRY: ghcr.io | ||
# レジストリのログインユーザー名 | ||
DOCKER_USERNAME: ${{ github.actor }} | ||
# レジストリのログインパスワード | ||
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} | ||
# ビルドするプラットフォーム | ||
PLATFORMS: linux/amd64,linux/arm64 | ||
# ビルド対象情報の情報 | ||
TARGETS: >- | ||
[ | ||
{ imageName: "tomacheese/watch-follow-follower", context: ".", file: "Dockerfile", packageName: "watch-follow-follower" } | ||
] | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.merged == true && 'master' || github.event.pull_request.head.sha }} | ||
|
@@ -47,6 +56,8 @@ jobs: | |
platform-matrix: ${{ steps.platform-matrix.outputs.matrix }} | ||
# latestタグへのマージが必要かどうか (複数のプラットフォームがある時は必要) | ||
need-merge: ${{ steps.platform-matrix.outputs.need-merge }} | ||
# ビルド対象情報のマトリクス | ||
targets-matrix: ${{ steps.targets-matrix.outputs.matrix }} | ||
|
||
steps: | ||
- name: Check out the repo | ||
|
@@ -61,8 +72,8 @@ jobs: | |
uses: mathieudutour/[email protected] | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
default_bump: 'minor' | ||
custom_release_rules: 'feat:minor:✨ Features,fix:patch:🐛 Fixes,docs:patch:📰 Docs,chore:patch:🎨 Chore,pref:patch:🎈 Performance improvements,refactor:patch:🧹 Refactoring,build:patch:🔍 Build,ci:patch:🔍 CI,revert:patch:⏪ Revert,style:patch:🧹 Style,test:patch:👀 Test,release:major:📦 Release' | ||
default_bump: "minor" | ||
custom_release_rules: "feat:minor:✨ Features,fix:patch:🐛 Fixes,docs:patch:📰 Docs,chore:patch:🎨 Chore,pref:patch:🎈 Performance improvements,refactor:patch:🧹 Refactoring,build:patch:🔍 Build,ci:patch:🔍 CI,revert:patch:⏪ Revert,style:patch:🧹 Style,test:patch:👀 Test,release:major:📦 Release" | ||
dry_run: ${{ github.event.pull_request.merged == false }} | ||
|
||
- name: Set platform matrix | ||
|
@@ -73,26 +84,33 @@ jobs: | |
# ,があるときはneed-merge=true | ||
echo "need-merge=$(echo "$PLATFORMS" | grep -q ',' && echo true || echo false)" >> $GITHUB_OUTPUT | ||
- name: Set targets matrix | ||
id: targets-matrix | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setOutput('matrix', process.env.TARGETS) | ||
env: | ||
TARGETS: ${{ env.TARGETS }} | ||
|
||
# Dockerイメージをビルドする | ||
build: | ||
name: Docker build (${{ fromJson(matrix.target).file }}, ${{ matrix.platform }}) | ||
name: Docker build (${{ matrix.target.packageName }}, ${{ matrix.platform }}) | ||
runs-on: ubuntu-latest | ||
needs: calc-version | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# ビルドするプラットフォーム | ||
platform: ${{ fromJson(needs.calc-version.outputs.platform-matrix) }} | ||
platform: ${{ fromJSON(needs.calc-version.outputs.platform-matrix) }} | ||
# ビルドするDockerfile | ||
target: | ||
- '{ imageName: "tomacheese/watch-follow-follower", file: "Dockerfile", packageName: "watch-follow-follower" }' | ||
target: ${{ fromJSON(needs.calc-version.outputs.targets-matrix) }} | ||
|
||
steps: | ||
- name: Remove platform prefix | ||
id: platform | ||
run: | ||
echo "shortPlatform=$(echo "${{ matrix.platform }}" | sed -r -e 's/^[^\/]+\///')" >> $GITHUB_OUTPUT | ||
run: echo "shortPlatform=$(echo "${{ matrix.platform }}" | sed -r -e 's/^[^\/]+\///')" >> $GITHUB_OUTPUT | ||
|
||
- name: Create GitHub deployment | ||
uses: chrnorm/[email protected] | ||
|
@@ -101,8 +119,8 @@ jobs: | |
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
ref: ${{ needs.calc-version.outputs.tag }} | ||
environment: '${{ fromJson(matrix.target).packageName }}:${{ steps.platform.outputs.shortPlatform }}' | ||
environment-url: https://github.com/${{ github.repository }}/pkgs/container/${{ fromJson(matrix.target).packageName }} | ||
environment: "${{ matrix.target.packageName }}:${{ steps.platform.outputs.shortPlatform }}" | ||
environment-url: https://github.com/${{ github.repository }}/pkgs/container/${{ matrix.target.packageName }} | ||
|
||
- name: Update deployment status (in_progress) | ||
uses: chrnorm/[email protected] | ||
|
@@ -134,13 +152,13 @@ jobs: | |
|
||
- name: package.json update version | ||
run: | | ||
sed -r -i "1,/version/s/\"version\": \".+\"/\"version\": \"${{ needs.calc-version.outputs.tag }}\"/" package.json | ||
find . -type d -name node_modules -prune -o -type f -name package.json -exec sed -r -i "1,/version/s/\"version\": \".+\"/\"version\": \"${{ needs.calc-version.outputs.tag }}\"/" {} \; | ||
git diff | ||
- name: Set tag suffix value | ||
id: tag | ||
run: | | ||
if [ "${{ fromJson(needs.calc-version.outputs.need-merge) }}" = "true" ]; then | ||
if [ "${{ needs.calc-version.outputs.need-merge }}" = "true" ]; then | ||
echo "suffix=-${{ steps.platform.outputs.shortPlatform }}" >> $GITHUB_OUTPUT | ||
else | ||
echo "suffix=" >> $GITHUB_OUTPUT | ||
|
@@ -150,7 +168,7 @@ jobs: | |
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ fromJson(matrix.target).imageName }} | ||
images: ${{ env.REGISTRY }}/${{ matrix.target.imageName }} | ||
tags: | | ||
# need-mergeがtrueの時はshortPlatformを含める (latest-arm64) | ||
# need-mergeがfalseの時はshortPlatformを含めない (latest) | ||
|
@@ -160,14 +178,14 @@ jobs: | |
- name: Build and push Docker image | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
file: ${{ fromJson(matrix.target).file }} | ||
context: ${{ matrix.target.context }} | ||
file: ${{ matrix.target.file }} | ||
push: ${{ github.event.pull_request.merged == true }} | ||
platforms: ${{ matrix.platform }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=gha,scope=${{ fromJson(matrix.target).packageName }}-${{ steps.platform.outputs.shortPlatform }} | ||
cache-to: type=gha,mode=max,scope=${{ fromJson(matrix.target).packageName }}-${{ steps.platform.outputs.shortPlatform }} | ||
cache-from: type=gha,scope=${{ matrix.target.packageName }}-${{ steps.platform.outputs.shortPlatform }} | ||
cache-to: type=gha,mode=max,scope=${{ matrix.target.packageName }}-${{ steps.platform.outputs.shortPlatform }} | ||
provenance: false | ||
|
||
- name: Update deployment status (success) | ||
|
@@ -186,9 +204,20 @@ jobs: | |
state: failure | ||
deployment-id: ${{ steps.deployment.outputs.deployment_id }} | ||
|
||
finished-build: | ||
name: Check finished build | ||
runs-on: ubuntu-latest | ||
needs: | ||
- calc-version | ||
- build | ||
|
||
steps: | ||
- name: Check finished build | ||
run: echo ok | ||
|
||
# 各プラットフォームのlatestからlatestタグにマージしてイメージを作成 | ||
merge-latest: | ||
name: Merge latest (${{ fromJson(matrix.target).file }}) | ||
name: Merge latest (${{ matrix.target.packageName }}) | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
needs: | ||
|
@@ -199,8 +228,7 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
# ビルドするDockerfile | ||
target: | ||
- '{ imageName: "tomacheese/watch-follow-follower", file: "Dockerfile", packageName: "watch-follow-follower" }' | ||
target: ${{ fromJSON(needs.calc-version.outputs.targets-matrix) }} | ||
|
||
steps: | ||
- name: Login to ${{ env.REGISTRY }} | ||
|
@@ -214,14 +242,15 @@ jobs: | |
- name: Create extra-images list | ||
id: extra-images | ||
run: | | ||
echo "images=$(echo "$PLATFORMS" | sed -r 's#([a-z]+)\/([a-z0-9]+)#${{ env.REGISTRY }}\/${{ fromJson(matrix.target).imageName }}:latest-\2#g')" >> $GITHUB_OUTPUT | ||
# linux/amd64,linux/arm64 -> ${{ env.REGISTRY }}/tomacheese/my-pixiv:latest-amd64,${{ env.REGISTRY }}/tomacheese/my-pixiv:latest-arm64 | ||
echo "images=$(echo "$PLATFORMS" | sed -r 's#([a-z]+)\/([a-z0-9]+)#${{ env.REGISTRY }}\/${{ matrix.target.imageName }}:latest-\2#g')" >> $GITHUB_OUTPUT | ||
- name: Create and push manifest images (latest) | ||
uses: Noelware/[email protected] | ||
# プラットフォームがひとつの場合はマージ処理を行わない | ||
if: ${{ needs.calc-version.outputs.need-merge == 'true' }} | ||
with: | ||
base-image: ${{ env.REGISTRY }}/${{ fromJson(matrix.target).imageName }}:latest | ||
base-image: ${{ env.REGISTRY }}/${{ matrix.target.imageName }}:latest | ||
extra-images: ${{ steps.extra-images.outputs.images }} | ||
push: true | ||
|
||
|
@@ -230,7 +259,7 @@ jobs: | |
# プラットフォームがひとつの場合はマージ処理を行わない | ||
if: ${{ needs.calc-version.outputs.need-merge == 'true' }} | ||
with: | ||
base-image: ${{ env.REGISTRY }}/${{ fromJson(matrix.target).imageName }}:${{ needs.calc-version.outputs.tag }} | ||
base-image: ${{ env.REGISTRY }}/${{ matrix.target.imageName }}:${{ needs.calc-version.outputs.tag }} | ||
extra-images: ${{ steps.extra-images.outputs.images }} | ||
push: true | ||
|
||
|
@@ -258,39 +287,3 @@ jobs: | |
body: ${{ needs.calc-version.outputs.changelog }} | ||
draft: false | ||
prerelease: false | ||
|
||
upload-package: | ||
name: Upload package ${{ needs.calc-version.outputs.tag }} | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
needs: | ||
- calc-version | ||
- build | ||
- merge-latest | ||
- release | ||
|
||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v3 | ||
with: | ||
# マージされていない時には github.event.pull_request.head.sha を使い、マージされた時にはmasterを使う | ||
ref: ${{ github.event.pull_request.merged == true && 'master' || github.event.pull_request.head.sha }} | ||
|
||
- name: 🏗 Setup node env | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: 🎁 Run package | ||
run: yarn package | ||
|
||
- name: Upload Release Asset | ||
uses: shogo82148/[email protected] | ||
with: | ||
upload_url: ${{ needs.release.outputs.upload_url }} | ||
asset_path: output/index.js | ||
asset_name: index.js | ||
asset_content_type: text/javascript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: hadolint | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
pull_request: | ||
branches: | ||
- main | ||
- master | ||
|
||
jobs: | ||
hadolint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout 🛎 | ||
uses: actions/checkout@v3 | ||
|
||
- uses: hadolint/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters