Squashed commit of the following: #36
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
# This workflow will build and publish Action Destination package and trigger a buildkite workflow. | |
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages | |
name: Publish Canary | |
on: | |
push: | |
branches: | |
# Remove before merging to master | |
- add-tar-release-pipeline | |
- staging | |
# Manual trigger | |
workflow_dispatch: | |
# branches: | |
# - add-tar-release-pipeline | |
# # inputs: | |
# # service_branch: | |
# # description: 'The service branch to update. If a branch is not present, a new branch will be created.' | |
# # required: true | |
# # default: 'stage' | |
jobs: | |
build-and-publish: | |
env: | |
HUSKY: 0 | |
runs-on: ubuntu-20.04 | |
timeout-minutes: 15 | |
strategy: | |
matrix: | |
node-version: [18.x] | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.GH_PAT }} | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
registry-url: 'https://registry.npmjs.org' | |
cache: yarn | |
- name: Use Github Personal Access Token | |
run: git config --global url."https://${{ secrets.GH_PAT }}@github.com/".insteadOf ssh://[email protected]/ | |
- name: Install Dependencies | |
run: yarn install --frozen-lockfile | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Build | |
run: | | |
NODE_ENV=production yarn build | |
- name: Set NPM Token | |
run: | | |
npm set '//registry.npmjs.org/:_authToken' ${{ secrets.NPM_PUBLISH_TOKEN }} | |
npm whoami | |
- name: Publish Canary Packages | |
id: publish-packages | |
run: | | |
yarn lerna publish -y --canary --preid "$(git branch --show-current)-$(git rev-parse --short HEAD)" --no-push --no-git-tag-version --summary-file | |
echo "ACTION_DESTINATIONS_VERSION=$(jq -r '.[] | select(.packageName == "@segment/action-destinations") | .version' lerna-publish-summary.json)" >> "$GITHUB_OUTPUT" | |
echo "ACTIONS_CORE_VERSION=$(jq -r '.[] | select(.packageName == "@segment/actions-core") | .version' lerna-publish-summary.json)" >> "$GITHUB_OUTPUT" | |
- name: Trigger Buildkite Pipeline | |
if: ${{ steps.publish-packages.outputs.ACTION_DESTINATIONS_VERSION != null && steps.publish-packages.outputs.ACTIONS_CORE_VERSION != null }} | |
env: | |
ACTION_DESTINATIONS_VERSION: ${{ steps.publish-packages.outputs.ACTION_DESTINATIONS_VERSION }} | |
ACTIONS_CORE_VERSION: ${{ steps.publish-packages.outputs.ACTIONS_CORE_VERSION }} | |
run: | | |
result=$(curl --request POST \ | |
--url "${{ vars.BUILDKITE_PIPELINE_URL }}" \ | |
--header 'Authorization: Bearer ${{ secrets.BUILDKITE_TOKEN }}' \ | |
--header 'Content-Type: application/json' \ | |
--data '{"commit":"HEAD","branch":"ci-test", "message": ":github: Triggered from Github Actions Run: ${{ github.run_id }}","env":{ | |
"BRANCH_TO_UPDATE": "${{ github.ref_name }}", "ACTIONS_RELEASE": "true", "CREATE_PR": "false", "UPGRADE_ACTION_DESTINATIONS": "true", "ACTION_DESTINATIONS_VERSION": "${{ env.ACTION_DESTINATIONS_VERSION }}", "ACTIONS_CORE_VERSION": "${{ env.ACTIONS_CORE_VERSION }}", "ACTIONS_RUN_ID": "${{ github.run_id }}" },"meta_data":{}}') | |
BUILDKITE_URL=$(echo $result | jq -r '.web_url') | |
if [[ "${BUILDKITE_URL}" -eq null ]]; then | |
echo "Failed to trigger Buildkite pipeline. Reason:$(echo $result | jq -r '.message')" | |
exit 1 | |
else | |
echo "Buildkite pipeline triggered successfully." | |
fi |