name: Tag a Build on: # schedule event triggers always run on the default branch # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule schedule: # run "nightly" builds on default branch every mon/wed/fri - cron: "21 2 * * 2,4,6" # 2:21am UTC tues/thurs/sat == 7:21pm PDT mon/wed/fri -- see https://crontab.guru/#21_01_*_*_2,4,6 workflow_dispatch: inputs: channel: description: "Channel to configure the build" required: true type: choice default: "Test" options: - "Test" - "Develop" - "Project" - "Release" project: description: "Project Name (used for channel name in project builds, and tag name for all builds)" default: "hippo" tag_override: description: "Override the tag name (optional). If the tag already exists, a numeric suffix is appended." required: false jobs: tag-release: runs-on: ubuntu-latest steps: - name: Setup Env Vars run: | CHANNEL="${{ inputs.channel }}" echo VIEWER_CHANNEL="Second_Life_${CHANNEL:-Develop}" >> ${GITHUB_ENV} NIGHTLY_DATE=$(date --rfc-3339=date) echo NIGHTLY_DATE=${NIGHTLY_DATE} >> ${GITHUB_ENV} echo TAG_ID="$(echo ${{ github.sha }} | cut -c1-8)-${{ inputs.project || '${NIGHTLY_DATE}' }}" >> ${GITHUB_ENV} - name: Create Tag uses: actions/github-script@v8 with: # use a real access token instead of GITHUB_TOKEN default. # required so that the results of this tag creation can trigger the build workflow # https://stackoverflow.com/a/71372524 # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow # this token will need to be renewed anually in January github-token: ${{ secrets.LL_TAG_RELEASE_TOKEN }} script: | const override = `${{ inputs.tag_override }}`.trim(); const baseTag = override || `${{ env.VIEWER_CHANNEL }}#${{ env.TAG_ID }}`; // Try the base tag first, then append -2, -3, etc. if it already exists let tag = baseTag; for (let attempt = 1; ; attempt++) { try { await github.rest.git.createRef({ owner: context.repo.owner, repo: context.repo.repo, ref: `refs/tags/${tag}`, sha: context.sha }); core.info(`Created tag: ${tag}`); break; } catch (e) { if (e.status === 422 && attempt < 10) { core.info(`Tag '${tag}' already exists, trying next suffix...`); tag = `${baseTag}-${attempt + 1}`; } else { throw e; } } }