fix: すべてのURLを書き直していた問題を修正 #1132
Workflow file for this run
This file contains hidden or 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
| # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | |
| name: build | |
| on: | |
| push: | |
| branches: [master] | |
| tags: ['*'] | |
| pull_request: | |
| branches: [master] | |
| jobs: | |
| act-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Block obsolete job execution | |
| run: | | |
| if [ -n "$ACT" ]; then | |
| echo "Running in act, some jobs are skipped" | |
| exit 1 | |
| else | |
| exit 0 | |
| fi | |
| continue-on-error: true | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: ['22.x'] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| - name: Cache node_modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: node_modules | |
| key: modules-cache-v1-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | |
| - run: npm install | |
| - run: npm run lint | |
| - run: npm run test | |
| - run: npm run build | |
| - name: save the built | |
| uses: actions/upload-artifact@v4 | |
| if: "!failure()" | |
| with: | |
| retention-days: 1 | |
| name: the-built | |
| path: | | |
| dist/ | |
| docs/ | |
| gh-pages: | |
| name: 'Host with GitHub Pages' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build | |
| - act-test | |
| if: ${{ github.ref == 'refs/heads/master' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.x' | |
| - name: Clean repo | |
| run: | | |
| git checkout --orphan gh-pages | |
| git rm -rf . > /dev/null 2>&1 | |
| - name: load the built | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: the-built | |
| - name: Setup and deploy Github Pages | |
| run: | | |
| rm -rf dist | |
| mv docs/* . | |
| git config user.name "$GITHUB_ACTOR" | |
| git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | |
| git add . > /dev/null 2>&1 | |
| git commit -m "Deploy" > /dev/null 2>&1 | |
| git push --force origin gh-pages | |
| publish: | |
| name: 'Publish npm package' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| needs: | |
| - build | |
| - act-test | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| tag_name: 'v%s' | |
| node-version: '22.x' | |
| registry-url: 'https://registry.npmjs.org' | |
| scope: '@geolonia' | |
| - name: load the built | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: the-built | |
| - name: Update npm | |
| run: npm install -g npm@latest | |
| - name: 'Publish to NPM (latest)' | |
| if: "!contains(github.ref, '-pre.')" | |
| run: npm publish --access=public | |
| - name: 'Publish to NPM (next)' | |
| if: "contains(github.ref, '-pre.')" | |
| run: npm publish --access=public --tag=next | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| # These permissions are needed to interact with GitHub's OIDC Token endpoint. | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - uses: actions/download-artifact@v4 | |
| with: { name: the-built, path: ./ } | |
| - name: Read version | |
| id: version | |
| run: | | |
| TAG=${GITHUB_REF#refs/tags/} | |
| VERSION=${TAG#v} | |
| MAJOR=$(echo $VERSION | cut -d. -f1) | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "major_version=$MAJOR" >> "$GITHUB_OUTPUT" | |
| - name: Restore timestamps | |
| uses: chetan/git-restore-mtime-action@v1 | |
| - name: Configure AWS Credentials for test | |
| if: ${{ env.ACT }} | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Configure AWS Credentials for deploy | |
| if: ${{ !env.ACT }} | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-region: ap-northeast-1 | |
| role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE }} | |
| - name: Deploy to S3 | |
| run: | | |
| # Note: The default max-age is set at 3600 seconds or 1 hour. After 1 hour, | |
| # the client will mark the resource as stale, and require a refresh. | |
| # In most cases, this will result in a if-modified-since conditional request. | |
| # For resources that are immutable (for example, embed-chunks), the max-age is set to immutable. | |
| # For resources that will be manually invalidated, an addition s-maxage so CloudFront keeps the file in its cache as long as possible. | |
| # Deploy embed chunks -- because they have fingerprints in the filename, they're immutable | |
| aws s3 sync ./dist/embed-chunks s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.major_version }}/embed-chunks --cache-control "public,max-age=31536000,immutable" | |
| aws s3 sync ./dist/embed-chunks s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.version }}/embed-chunks --cache-control "public,max-age=31536000,immutable" | |
| # Deploy main embed entrypoint | |
| # I used to use s-maxage here, but after testing decided to revert back to only using max-age. | |
| # If you use s-maxage that is much longer than max-age, the age header will be longer than | |
| # max-age, and the browser will think that the file is expired. Using max-age will make | |
| # CloudFront fetch a new file every 3600 seconds, resetting the Age header | |
| aws s3 cp ./dist/embed s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.major_version }}/embed --cache-control "public,max-age=3600" --content-type "application/javascript; charset=UTF-8" | |
| aws s3 cp ./dist/embed.js.LICENSE.txt s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.major_version }}/embed.js.LICENSE.txt --cache-control "public,max-age=3600" --content-type "text/plain; charset=UTF-8" | |
| aws s3 cp ./dist/embed s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.version }}/embed --cache-control "public,max-age=3600" --content-type "application/javascript; charset=UTF-8" | |
| aws s3 cp ./dist/embed.js.LICENSE.txt s3://${{ secrets.CDN_BUCKET }}/embed/v${{ steps.version.outputs.version }}/embed.js.LICENSE.txt --cache-control "public,max-age=3600" --content-type "text/plain; charset=UTF-8" | |
| aws cloudfront create-invalidation --distribution-id "${{ secrets.AWS_CLOUDFRONT_DISTRIBUTION_ID }}" --paths "/embed/v${{ steps.version.outputs.major_version }}/embed" "/embed/v${{ steps.version.outputs.version }}/embed" |