|
| 1 | +name: Tag or Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # a push to main updating package.json will check if a new tag is needed |
| 6 | + branches: ["main"] |
| 7 | + paths: ["package.json"] |
| 8 | + |
| 9 | + # a push of a tag will trigger a deployment |
| 10 | + tags: ["v*"] |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Determine Release Mode |
| 26 | + id: mode |
| 27 | + run: | |
| 28 | + # 1. Check if we are triggered by a TAG push |
| 29 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 30 | + echo "Triggered by manual tag: ${{ github.ref_name }}" |
| 31 | + echo "do_deploy=true" >> $GITHUB_OUTPUT |
| 32 | + echo "do_tag=false" >> $GITHUB_OUTPUT |
| 33 | + echo "tag_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | +
|
| 37 | + # 2. If triggered by BRANCH push, check package.json |
| 38 | + VERSION=$(jq -r .version package.json) |
| 39 | + TAG="v$VERSION" |
| 40 | + |
| 41 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 42 | + echo "Tag $TAG already exists in repo. Assuming manual release triggered separately." |
| 43 | + echo "do_deploy=false" >> $GITHUB_OUTPUT |
| 44 | + echo "do_tag=false" >> $GITHUB_OUTPUT |
| 45 | + else |
| 46 | + echo "New version $VERSION detected in package.json. Starting auto-release." |
| 47 | + echo "do_deploy=true" >> $GITHUB_OUTPUT |
| 48 | + echo "do_tag=true" >> $GITHUB_OUTPUT |
| 49 | + echo "tag_name=$TAG" >> $GITHUB_OUTPUT |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Setup Node |
| 53 | + if: steps.mode.outputs.do_deploy == 'true' |
| 54 | + uses: actions/setup-node@v4 |
| 55 | + with: |
| 56 | + node-version: '20' |
| 57 | + cache: 'npm' |
| 58 | + |
| 59 | + - name: Install Dependencies |
| 60 | + if: steps.mode.outputs.do_deploy == 'true' |
| 61 | + run: npm ci |
| 62 | + |
| 63 | + - name: Build Project |
| 64 | + if: steps.mode.outputs.do_deploy == 'true' |
| 65 | + run: | |
| 66 | + npm run clean |
| 67 | + npm run bundle |
| 68 | + npm run generate-licenses |
| 69 | + npm run build:docs |
| 70 | +
|
| 71 | + - name: Prepare Artifacts |
| 72 | + if: steps.mode.outputs.do_deploy == 'true' |
| 73 | + run: | |
| 74 | + mkdir dist |
| 75 | + cp index.html dist/ |
| 76 | + cp fsedit/index.html dist/ |
| 77 | + cp recover_fs/index.html dist/ |
| 78 | + cp -r docs dist/ |
| 79 | + cp -r public dist/ |
| 80 | + cp CNAME dist/ || true |
| 81 | + cp _config.yml dist/ || true |
| 82 | + cp robots.txt dist/ || true |
| 83 | + cp LICENSE dist/ || true |
| 84 | + cp .nojekyll dist/ || true |
| 85 | +
|
| 86 | + - name: Deploy to GitHub Pages |
| 87 | + uses: JamesIves/github-pages-deploy-action@v4 |
| 88 | + with: |
| 89 | + branch: gh-pages |
| 90 | + folder: dist |
| 91 | + clean: true |
| 92 | + |
| 93 | + # ONLY runs if we are in "Auto Mode" (Branch push), NOT manual tag mode |
| 94 | + - name: Auto-Create Git Tag |
| 95 | + if: steps.mode.outputs.do_tag == 'true' |
| 96 | + run: | |
| 97 | + git config user.name "github-actions[bot]" |
| 98 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 99 | + |
| 100 | + TAG="${{ steps.mode.outputs.tag_name }}" |
| 101 | + git tag -a "$TAG" -m "Auto-release $TAG" |
| 102 | + git push origin "$TAG" |
0 commit comments