Merge pull request #14 from Quantco/handle-initial-commits #44
This file contains 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: Build | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
commit-version-metadata: | |
name: Commit changes of version-metadata build output | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: version-metadata | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pnpm/[email protected] | |
with: | |
version: 8.11.0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20.x | |
cache: pnpm | |
- run: pnpm install | |
- run: pnpm lint | |
- run: pnpm build | |
- run: pnpm licenses list --filter "version-metadata" --prod --json | npx @quantco/pnpm-licenses generate-disclaimer --json-input --output-file version-metadata/dist/licenses.txt | |
- name: Commit changes | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git pull # the other action might have created a commit already, better pull :) | |
git add --force dist # have to use --force because dist is in .gitignore | |
git commit -m "[auto] build version-metadata: update compiled version" || true # don't fail if there are no changes | |
git push | |
commit-publish: | |
name: Commit changes of publish build output | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
working-directory: publish | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pnpm/[email protected] | |
with: | |
version: 8.11.0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: 20.x | |
cache: pnpm | |
- run: pnpm install | |
- run: pnpm lint | |
- run: pnpm build | |
- run: pnpm licenses list --filter "publish" --prod --json | npx @quantco/pnpm-licenses generate-disclaimer --json-input --output-file publish/dist/licenses.txt | |
- name: Commit changes | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
git pull # the other action might have created a commit already, better pull :) | |
git add --force dist # have to use --force because dist is in .gitignore | |
git commit -m "[auto] build publish: update compiled version" || true # don't fail if there are no changes | |
git push | |
push-tags: | |
name: Push tags | |
runs-on: ubuntu-latest | |
needs: [commit-version-metadata, commit-publish] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: Quantco/ui-actions/version-metadata@v1 | |
id: version-metadata | |
with: | |
# the version of both actions should be kept in sync | |
# this is enforced by the sanity check step below | |
file: version-metadata/package.json | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: Quantco/ui-actions/version-metadata@v1 | |
id: version-metadata-sanity-check | |
with: | |
file: publish/package.json | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Sanity version check | |
if: steps.version-metadata.outputs.newVersion != steps.version-metadata-sanity-check.outputs.newVersion | |
run: | | |
echo "version-metadata and publish version do not match" | |
echo "version-metadata:" | |
echo "old: '${{ steps.version-metadata.outputs.oldVersion }}'" | |
echo "new: '${{ steps.version-metadata.outputs.newVersion }}'" | |
echo "changed: '${{ steps.version-metadata.outputs.changed }}'" | |
echo "type: '${{ steps.version-metadata.outputs.type }}'" | |
echo "publish:" | |
echo "old: '${{ steps.version-metadata-sanity-check.outputs.oldVersion }}'" | |
echo "new: '${{ steps.version-metadata-sanity-check.outputs.newVersion }}'" | |
echo "changed: '${{ steps.version-metadata-sanity-check.outputs.changed }}'" | |
echo "type: '${{ steps.version-metadata-sanity-check.outputs.type }}'" | |
exit 1 | |
- name: Configure git and pull auto build commits | |
run: | | |
# configure git to use the github-actions[bot] user | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
# pull auto build commits | |
git pull | |
# fetch all tags | |
git fetch --tags | |
- name: Push v(x.x.x) tag | |
if: steps.version-metadata.outputs.changed == 'true' | |
run: | | |
version="${{ steps.version-metadata.outputs.newVersion }}" | |
git tag "v${version}" | |
git push origin "v${version}" | |
echo "pushed v${version} tag" >> $GITHUB_STEP_SUMMARY | |
- name: Update v(x) tag (move) | |
if: steps.version-metadata.outputs.changed == 'true' && steps.version-metadata.outputs.type != 'major' | |
run: | | |
# compute major version | |
version="${{ steps.version-metadata.outputs.newVersion }}" | |
major="${version%%.*}" # see https://www.linuxjournal.com/article/8919 for an explanation of this bash magic | |
# delete the v(x) tag locally and on the remote | |
git tag -d "v${major}" || echo "couldn't delete tag v${major} locally, maybe it didn't exist before, continuing.." | |
git push origin ":refs/tags/v${major}" || echo "couldn't delete tag v${major} remotely, maybe it didn't exist before, continuing.." | |
git tag "v${major}" | |
git push origin "v${major}" | |
echo "moved v${major} tag to v${version}" >> $GITHUB_STEP_SUMMARY | |
- name: Update v(x) tag (major version bump) | |
if: steps.version-metadata.outputs.changed == 'true' && steps.version-metadata.outputs.type == 'major' | |
run: | | |
# compute major version | |
version="${{ steps.version-metadata.outputs.newVersion }}" | |
major="${version%%.*}" | |
git tag "v${major}" | |
git push origin "v${major}" | |
echo "pushed v${major} tag" >> $GITHUB_STEP_SUMMARY | |
- name: Report no changes | |
if: steps.version-metadata.outputs.changed == 'false' | |
run: | | |
echo "No version bump detected" >> $GITHUB_STEP_SUMMARY |