1.0.11 #2
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
| name: Release Packages | |
| on: | |
| release: | |
| types: [released] | |
| env: | |
| NODE_VERSION: "20.16.0" | |
| PHP_VERSION: "8.2.22" | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| defaults: | |
| run: | |
| working-directory: ./krait-ui | |
| concurrency: | |
| group: release | |
| cancel-in-progress: false | |
| jobs: | |
| bump_version: | |
| name: Build UI | |
| runs-on: "ubuntu-22.04" | |
| outputs: | |
| version_branch: ${{ steps.get-version-details.outputs.major_version}}.x | |
| steps: | |
| - name: Get Github token | |
| id: get-github-token | |
| uses: peter-murray/workflow-application-token-action@v3 | |
| with: | |
| application_id: ${{ vars.GH_MTR_PACKAGE_VERSIONS_APP_ID }} | |
| application_private_key: ${{ secrets.GH_MTR_PACKAGE_VERSIONS_APP_SECRET }} | |
| - name: Get release version details | |
| id: get-version-details | |
| run: | | |
| # Extract major version (handles v1.2.3-beta.0 or 1.2.3-beta.0) | |
| MAJOR_VERSION=$(echo "${{ github.event.release.tag_name }}" | sed 's/^v\{0,1\}\([0-9]\+\)[^0-9].*/\1/') | |
| echo "major_version=$MAJOR_VERSION" >> $GITHUB_OUTPUT | |
| - name: Checkout the repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ steps.get-version-details.outputs.major_version}}.x | |
| token: ${{ steps.get-github-token.outputs.token }} | |
| - name: Verify the release title | |
| env: | |
| RELEASE_TITLE: ${{ github.event.release.name }} | |
| run: | | |
| if [[ -z "$RELEASE_TITLE" ]]; then | |
| echo "Release title cannot be empty" | |
| exit 1 | |
| fi | |
| TITLE_VERSION_REGEX="^v[0-9]+\.[0-9]+\.[0-9]+$" | |
| if [[ ! $RELEASE_TITLE =~ $TITLE_VERSION_REGEX ]]; then | |
| echo "Invalid release title format: $RELEASE_TITLE" | |
| exit 1 | |
| else | |
| echo "Release title $RELEASE_TITLE is valid" | |
| fi | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| - name: Update package.json version | |
| env: | |
| VERSION: ${{ github.event.release.tag_name }} | |
| run: | | |
| npm version $VERSION | |
| - name: Commit the version bump update | |
| env: | |
| VERSION: ${{ github.event.release.tag_name }} | |
| GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }} | |
| run: | | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config user.name "github-actions[bot]" | |
| git add . | |
| git commit -am "[GHA] Update package version to $VERSION" | |
| git push origin HEAD:$CLEAN_VERSION | |
| release: | |
| name: Release Package | |
| runs-on: ubuntu-22.04 | |
| needs: [bump_version] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.bump_version.outputs.version_branch }} | |
| - name: Download the production build | |
| id: download-production-build | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const fs = require('fs').promises; | |
| const artifact_name = 'distribution-package.zip'; | |
| const download_path = 'krait-ui/distribution-package.zip'; | |
| // Get the release assets | |
| const release = await github.rest.repos.getReleaseByTag({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| tag: context.payload.release.tag_name | |
| }); | |
| // Find the specific asset | |
| const asset = release.data.assets.find(asset => asset.name === artifact_name); | |
| if (!asset) throw new Error(`Asset ${artifact_name} not found in release`); | |
| // Download the asset | |
| const response = await github.rest.repos.getReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: asset.id, | |
| headers: { | |
| Accept: 'application/octet-stream' | |
| } | |
| }); | |
| // Save the file | |
| await fs.writeFile(download_path, Buffer.from(response.data)); | |
| console.log(`Downloaded ${artifact_name} to ${download_path}`); | |
| return asset.id | |
| - name: Update zip with new package.json | |
| working-directory: krait-ui | |
| run: | | |
| zip -u distribution-package.zip package.json package-lock.json | |
| - name: Delete existing release asset | |
| uses: actions/github-script@v6 | |
| env: | |
| ASSET_ID: ${{ steps.download-production-build.outputs.result }} | |
| with: | |
| script: | | |
| const {ASSET_ID} = process.env | |
| await github.rest.repos.deleteReleaseAsset({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| asset_id: ASSET_ID | |
| }); | |
| - name: Upload an Asset in GitHub Release | |
| uses: actions/github-script@v6 | |
| env: | |
| RELEASE_ID: ${{ github.event.release.id }} | |
| with: | |
| script: | | |
| const {RELEASE_ID} = process.env | |
| const fs = require('fs').promises; | |
| await github.rest.repos.uploadReleaseAsset({ | |
| name: 'distribution-package.zip', | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| release_id: ${{ env.RELEASE_ID }}, | |
| data: await fs.readFile('./krait-ui/distribution-package.zip') | |
| }); | |
| - name: Unzip the distribution build | |
| working-directory: krait-ui | |
| run: | | |
| unzip -n distribution-package.zip | |
| # - name: Publish the NPM package | |
| # run: npm publish --access public | |
| # env: | |
| # NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} | |
| - name: Release cleanup | |
| id: update-release | |
| uses: ./.github/actions/release-cleanup | |
| with: | |
| release_id: ${{ github.event.release.id }} | |
| tag_name: ${{ needs.bump_version.outputs.release_version }} | |
| node_auth_token: ${{ secrets.NPM_AUTH_TOKEN }} |