Skip to content

Merge branch 'master' into oserhiienko/admetica-test-fix #756

Merge branch 'master' into oserhiienko/admetica-test-fix

Merge branch 'master' into oserhiienko/admetica-test-fix #756

Workflow file for this run

name: Tools Package
on:
workflow_dispatch: { }
push:
paths:
- 'tools/**'
pull_request:
paths:
- 'tools/**'
jobs:
common-check:
name: Common checks
uses: ./.github/workflows/common_check.yaml
with:
run_trigger: ${{ github.event_name }}
check:
needs: common-check
runs-on: ubuntu-22.04
if: needs.common-check.outputs.continue == 'true'
name: Check version was changed
outputs:
changed_version: ${{ steps.check-version.outputs.changed_version }}
version: ${{ steps.check-version.outputs.version }}
job_name: ${{ steps.check-version.outputs.job_name }}
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
tools
- name: Check version was changed
id: check-version
working-directory: ./tools
run: |
name="$(jq .name package.json | sed 's/"//g')"
current_version="$(jq .version package.json | sed 's/"//g')"
npm_version="$(curl --retry 3 -s "https://registry.npmjs.org/${name}/${current_version}" | jq -r '.? | select( has("version") == true ).version')"
job_name="Build"
if [[ $npm_version == ${current_version} ]]; then
changed_version='false'
echo "Package $name version ${current_version} already published"
echo "::notice title=${name}::Version ${current_version} is already published"
else
if [[ ${{ github.ref }} == 'refs/heads/master' ]]; then
changed_version='true'
job_name="Build and publish to NPM"
else
echo "It is an actions for development branch. Publish will be skipped"
echo "::notice title=${name}::It is an actions for development branch. Publish will be skipped"
fi
fi
echo "job_name=${job_name}" >> $GITHUB_OUTPUT
echo "changed_version=${changed_version}" >> $GITHUB_OUTPUT
echo "version=${current_version}" >> $GITHUB_OUTPUT
build:
name: ${{ needs.version.outputs.job_name || 'Deploy' }}
needs: [ check, common-check ]
runs-on: ubuntu-22.04
if: needs.common-check.outputs.continue == 'true'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.WRITE_TOKEN || github.token }}
sparse-checkout: |
./tools
./.github
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
cache-dependency-path: |
tools/package-lock.json
- name: Upgrade npm
run: npm install -g npm@x
- run: npm version
- run: npm install
working-directory: ./tools
- run: npm publish
id: publish
working-directory: ./tools
if: needs.check.outputs.changed_version == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get actors slack
id: actor
uses: ./.github/actions/slack-user-action
with:
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
email-mapping: ${{ secrets.EMAIL_SLACK_ID }}
- name: Get owners slack
id: owner
uses: ./.github/actions/slack-user-action
with:
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
emails: "[email protected]"
- name: Prepare Slack Message
id: slack-prepare
if: ${{ steps.publish.outcome == 'success' }}
shell: bash
run: |
mentions=$(echo -e "${{ steps.actor.outputs.user-ids }}\n${{ steps.owner.outputs.user-ids }}" | sort -u)
header="*datagrok-tools* version *${{ needs.check.outputs.version }}* published to <https://www.npmjs.com/package/$(jq -r .name package.json)/v/${{ needs.check.outputs.version }}|NPM>\n$(for value in $mentions; do echo -n "<@$value> "; done) FYI"
echo "SLACK_MESSAGE_HEADER=$header" >> $GITHUB_ENV
- name: Send to Slack
id: slack
if: steps.slack-prepare.outcome == 'success'
uses: ./.github/actions/slack-post-action
with:
channel: '#build'
slack-token: ${{ secrets.SLACKBOT_TOKEN }}
message: ${{ env.SLACK_MESSAGE_HEADER }}
- name: Commit package-lock.json
continue-on-error: true
if: github.ref == 'refs/heads/master' && needs.check.outputs.changed_version == 'true'
run: |
if [ -n "$(git status -s tools/package-lock.json)" ]; then
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git pull
git add tools/package-lock.json
git commit -m 'GitHub Actions: Update tools/package-lock.json [skip ci]
Workflow ${{ github.workflow }} ${{ github.run_number }}
https://github.com/datagrok-ai/public/actions/runs/${{ github.run_id }}'
count=0
until git push; do
exit=$?
wait=$((2 ** count))
count=$((count + 1))
if [ $count -lt "10" ]; then
echo "Retry $count/$retries exited $exit, retrying 'git push' in $wait seconds..."
sleep $wait
git pull --rebase
else
echo "Retry $count/$retries exited $exit, no more retries left for 'git push'."
exit $exit
fi
done
fi