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

リリースをtagでのみ行うことにする #333

Merged
merged 5 commits into from
Dec 8, 2023
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
79 changes: 32 additions & 47 deletions .github/workflows/cd-for-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,40 @@ on:
- main
workflow_dispatch:

env:
DOCKER_TAG_API_URI: https://registry.hub.docker.com/v2/repositories/na2na/jetdisc/tags

jobs:
Prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
tag_exists: ${{ steps.check_docker_hub.outputs.tag_exists }}
JETDISC_VERSION: ${{ steps.check_docker_hub.outputs.JETDISC_VERSION }}
PREVIOIUS_LATEST_TAG: ${{ steps.get_previous_latest_tag.outputs.PREVIOIUS_LATEST_TAG }}
LATEST_TAG: ${{ steps.genelate_latest_tag.outputs.LATEST_TAG }}
prepare:
timeout-minutes: 60
runs-on:
- ubuntu-latest
steps:
- name: Check out the repo
- uses: actions/[email protected]
- name: Checkout repository
uses: actions/[email protected]
- name: Get current version
id: get_version
run: |
echo "JETDISC_VERSION=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV
- name: Check Docker Hub
id: check_docker_hub
# NOTE: 実験用にすでに存在しててもOUTPUT吐き出す
run: |
DOCKER_HUB_TAGS=$(curl -s ${{ env.DOCKER_TAG_API_URI }} | jq -r '.results[] | .name')
if echo "$DOCKER_HUB_TAGS" | grep -q "^$JETDISC_VERSION$"; then
echo "Tag $JETDISC_VERSION already exists on Docker Hub."
echo "JETDISC_VERSION=$JETDISC_VERSION" >> $GITHUB_OUTPUT
else
echo "Tag $JETDISC_VERSION does not exist on Docker Hub."
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "JETDISC_VERSION=$JETDISC_VERSION" >> $GITHUB_OUTPUT
fi
- name: Get Current Latest Tag
id: get_previous_latest_tag
- name: Setup asdf
uses: asdf-vm/actions/[email protected]
continue-on-error: true
- name: install ffmpeg dependencies
run: |
echo "PREVIOIUS_LATEST_TAG=$(curl -s $DOCKER_TAG_API_URI | jq -r '.results | sort_by(.last_updated) | last | .name')" >> $GITHUB_OUTPUT
- name: Genelate Latest Tag by commit hash
id: genelate_latest_tag
run: |
echo "LATEST_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

Build-and-Push-to-Docker-Hub:
needs:
- Prepare
# if: ${{ needs.Prepare.outputs.tag_exists == 'false' }}
with:
JETDISC_VERSION: ${{ needs.Prepare.outputs.JETDISC_VERSION }}
IMAGE_REPOSITORY: na2na
IMAGE_NAME: jetdisc
LATEST_TAG: ${{ needs.Prepare.outputs.LATEST_TAG }}
uses: ./.github/workflows/image-build-and-publish.yml
sudo apt-get update
sudo apt-get install -y nasm
- name: Cache asdf
uses: actions/cache@v3
with:
path: |
~/.asdf
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}
- name: asdf install
uses: asdf-vm/actions/[email protected]
ci:
uses: ./.github/workflows/ci.yml
secrets: inherit
needs: prepare
image-build-for-ci:
uses: ./.github/workflows/image-build.yml
secrets: inherit
image-scan:
uses: ./.github/workflows/image-scan.yml
secrets: inherit
needs: image-build-for-ci
with:
docker_image_tag_ci: ${{ needs.image-build-for-ci.outputs.docker_image_tag_ci }}
57 changes: 57 additions & 0 deletions .github/workflows/cd-for-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CD for tag

on:
push:
tags:
- '*'

env:
DOCKER_TAG_API_URI: https://registry.hub.docker.com/v2/repositories/na2na/jetdisc/tags

jobs:
Prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
tag_exists: ${{ steps.check_docker_hub.outputs.tag_exists }}
JETDISC_VERSION: ${{ steps.check_docker_hub.outputs.JETDISC_VERSION }}
PREVIOIUS_LATEST_TAG: ${{ steps.get_previous_latest_tag.outputs.PREVIOIUS_LATEST_TAG }}
LATEST_TAG: ${{ steps.genelate_latest_tag.outputs.LATEST_TAG }}
steps:
- name: Check out the repo
uses: actions/[email protected]
- name: Get current version
id: get_version
run: |
echo "JETDISC_VERSION=$(cat package.json | jq -r '.version')" >> $GITHUB_ENV
- name: Check Docker Hub
id: check_docker_hub
run: |
DOCKER_HUB_TAGS=$(curl -s ${{ env.DOCKER_TAG_API_URI }} | jq -r '.results[] | .name')
if echo "$DOCKER_HUB_TAGS" | grep -q "^$JETDISC_VERSION$"; then
echo "Tag $JETDISC_VERSION already exists on Docker Hub."
else
echo "Tag $JETDISC_VERSION does not exist on Docker Hub."
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "JETDISC_VERSION=$JETDISC_VERSION" >> $GITHUB_OUTPUT
fi
- name: Get Current Latest Tag
id: get_previous_latest_tag
run: |
echo "PREVIOIUS_LATEST_TAG=$(curl -s $DOCKER_TAG_API_URI | jq -r '.results | sort_by(.last_updated) | last | .name')" >> $GITHUB_OUTPUT
- name: Genelate Latest Tag by commit hash
id: genelate_latest_tag
run: |
echo "LATEST_TAG=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Build-and-Push-to-Docker-Hub:
needs:
- Prepare
if: ${{ needs.Prepare.outputs.tag_exists == 'false' }}
with:
JETDISC_VERSION: ${{ needs.Prepare.outputs.JETDISC_VERSION }}
IMAGE_REPOSITORY: na2na
IMAGE_NAME: jetdisc
LATEST_TAG: ${{ needs.Prepare.outputs.LATEST_TAG }}
RELEASE: true
uses: ./.github/workflows/image-build-and-publish.yml
secrets: inherit
5 changes: 4 additions & 1 deletion .github/workflows/image-build-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
LATEST_TAG:
required: true
type: string
RELEASE:
type: boolean
default: false
secrets: {}

jobs:
Expand Down Expand Up @@ -52,5 +55,5 @@ jobs:
--builder="${{ steps.buildx.outputs.name }}" \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.JETDISC_VERSION }}' \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:${{ inputs.LATEST_TAG }}' \
--set='app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:release' \
${{ inputs.RELEASE && '--set=app.tags=${{ inputs.IMAGE_REPOSITORY }}/${{ inputs.IMAGE_NAME }}:release' || '' }}
--push
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetdisc",
"version": "3.0.1",
"version": "3.0.2",
"description": "",
"type": "module",
"main": "built/index.js",
Expand Down
Loading