Merge pull request #108 from hico-horiuchi/update_nodejs_to_22.14.0 #235
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
name: Delivery | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
# https://github.com/actions/setup-node | |
- uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version-file: .node-version | |
- name: install dependencies | |
run: npm ci --production | |
- name: build assets | |
run: npm run build | |
# https://github.com/actions/upload-artifact | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: public_${{ github.sha }} | |
path: public/* | |
retention-days: 1 | |
deploy: | |
runs-on: ubuntu-latest | |
if: ${{ contains(github.event.pull_request.labels.*.name, 'dependencies') == false }} | |
needs: | |
- build | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
# https://github.com/actions/setup-node | |
- uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version-file: .node-version | |
# https://github.com/actions/download-artifact | |
- uses: actions/download-artifact@v4 | |
with: | |
name: public_${{ github.sha }} | |
path: public | |
# https://github.com/google-github-actions/auth | |
- uses: google-github-actions/auth@v2 | |
with: | |
create_credentials_file: true | |
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} | |
- name: install firebase-tools | |
run: npm install -g firebase-tools@$(node -p -e "require('./package.json').devDependencies['firebase-tools']") | |
- name: create firebase hosting channel | |
if: ${{ github.event_name == 'pull_request' }} | |
run: | | |
channel=$(echo ${{ github.head_ref }} | tr _ -) | |
firebase hosting:channel:create ${channel} | |
continue-on-error: true | |
- name: deploy to firebase hosting channel | |
if: ${{ github.event_name == 'pull_request' }} | |
run: | | |
channel=$(echo ${{ github.head_ref }} | tr _ -) | |
firebase hosting:channel:deploy ${channel} | |
- name: deploy to firebase | |
if: ${{ github.event_name == 'push' }} | |
run: firebase deploy | |
notify: | |
runs-on: ubuntu-latest | |
needs: | |
- deploy | |
if: >- | |
${{ | |
contains(github.event.pull_request.labels.*.name, 'dependencies') == false && | |
github.event_name == 'pull_request' | |
}} | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
# https://github.com/actions/setup-node | |
- uses: actions/setup-node@v4 | |
with: | |
cache: npm | |
node-version-file: .node-version | |
# https://github.com/google-github-actions/auth | |
- uses: google-github-actions/auth@v2 | |
with: | |
create_credentials_file: true | |
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} | |
- name: install firebase-tools | |
run: npm install -g firebase-tools@$(node -p -e "require('./package.json').devDependencies['firebase-tools']") | |
- name: set url for firebase hosting channel | |
id: firebase_hosting_channel_open | |
run: | | |
channel=$(echo ${{ github.head_ref }} | tr _ -) | |
url=$(firebase hosting:channel:open ${channel} | awk '{ print $3 }') | |
echo "url=${url}" >> ${GITHUB_OUTPUT} | |
# https://github.com/actions/github-script | |
- uses: actions/github-script@v7 | |
env: | |
URL: ${{ steps.firebase_hosting_channel_open.outputs.url }} | |
with: | |
script: | | |
const body = `Preview: ${process.env.URL}` | |
const options = github.rest.issues.listComments.endpoint.merge({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number | |
}) | |
const comments = await github.paginate(options) | |
const comment = comments.find(c => c.body == body) | |
if (comment) { | |
return | |
} | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body: body | |
}) | |
security_check: | |
runs-on: ubuntu-latest | |
steps: | |
# https://github.com/actions/checkout | |
- uses: actions/checkout@v4 | |
# https://github.com/aquasecurity/trivy-action | |
- uses: aquasecurity/[email protected] | |
with: | |
scan-ref: package-lock.json | |
scan-type: fs | |
trivy-config: .trivy.yaml |