diff --git a/.github/workflows/build-new-release.yml b/.github/workflows/build-new-release.yml new file mode 100644 index 0000000000..fe022d3eae --- /dev/null +++ b/.github/workflows/build-new-release.yml @@ -0,0 +1,67 @@ +name: Build New Release + +on: + pull_request: + types: [closed] + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 15 + if: ${{ github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'release') }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'yarn' + - name: Get version + id: get-version + run: | + echo "version=$(printf '%s' '${{ github.event.pull_request.title }}' | awk '{print $3}')" >> $GITHUB_OUTPUT + - name: Set git config + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + - name: Get commit msg + id: get-commit-msg + run: | + if [[ -z "${{ steps.get-version.outputs.version }}" ]]; then + echo "msg=deploy: $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "title-deploy=Deploy ref $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + else + echo "msg=deploy: version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "title-deploy=Deploy version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + fi + - name: Yarn install + run: | + yarn install --immutable --immutable-cache + - name: Setup .env + run: | + printf '%s' "$ENVFILE" > apps/frontend/.env.local + env: + ENVFILE: ${{ vars.ENVFILE }} + - name: Build genshin-optimizer + run: | + NX_URL_GITHUB_GO_CURRENT_VERSION="https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)" \ + yarn run nx run frontend:build-vite:production + - name: Create Deploy PR + run: | + git fetch origin gh-pages --depth=1 + git worktree add ../gh-pages gh-pages --no-checkout + cp -rT dist/apps/frontend ../gh-pages + cd ../gh-pages + git add --all . + git commit -m "${{ steps.get-commit-msg.outputs.msg }}" + git push origin HEAD:actions/deploy-gh-pages --force + gh pr create --base gh-pages --head actions/deploy-gh-pages --title '${{ steps.get-commit-msg.outputs.title-deploy }}' --body '' + env: + GH_TOKEN: ${{ github.token }} + - name: Make release + if: steps.get-version.outputs.version != '' + run: | + gh release create ${{ steps.get-version.outputs.version }} --generate-notes --target $(git rev-parse HEAD) + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/new-release.yml b/.github/workflows/new-release.yml index d5809f10d3..56a46b1bf1 100644 --- a/.github/workflows/new-release.yml +++ b/.github/workflows/new-release.yml @@ -10,17 +10,11 @@ on: jobs: deploy: runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 10 steps: - name: Checkout uses: actions/checkout@v4 - with: - submodules: true - - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: 'yarn' - - name: Get version # TODO(eeeqeee) add option to increment from current version + - name: Get version id: get-version run: | echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT @@ -40,38 +34,14 @@ jobs: id: get-commit-msg run: | if [[ -z "${{ steps.get-version.outputs.version }}" ]]; then - echo "msg=deploy: $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "title-release=Release ref $(git rev-parse HEAD)" >> $GITHUB_OUTPUT else - echo "msg=deploy: version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT + echo "title-release=Release version ${{ steps.get-version.outputs.version }} $(git rev-parse HEAD)" >> $GITHUB_OUTPUT fi - - name: Yarn install - run: | - yarn install --immutable --immutable-cache - - name: Setup .env - run: | - printf '%s' "$ENVFILE" > apps/frontend/.env.local - env: - ENVFILE: ${{ vars.ENVFILE }} - - name: Build genshin-optimizer - run: | - NX_URL_GITHUB_GO_CURRENT_VERSION="https://github.com/${{ github.repository }}/commit/$(git rev-parse HEAD)" \ - yarn run nx run frontend:build-vite:production - - name: Deploy to Github Pages - run: | - git fetch origin gh-pages --depth=1 - git worktree add ../gh-pages gh-pages --no-checkout - cp -rT dist/apps/frontend ../gh-pages - cd ../gh-pages - git add --all . - git commit -m "${{ steps.get-commit-msg.outputs.msg }}" - git push - - name: Push + - name: Create PR run: | git status - git push - - name: Make release - if: steps.get-version.outputs.version != '' - run: | - gh release create ${{ steps.get-version.outputs.version }} --generate-notes --target $(git rev-parse HEAD) + git push origin HEAD:actions/new-release --force + gh pr create --base $(git rev-parse --abbrev-ref HEAD) --head actions/new-release --title '${{ steps.get-commit-msg.outputs.title-release }}' --body '' --label release env: GH_TOKEN: ${{ github.token }}