Merge pull request #4 from Platform-OS/do-not-publish-event-twice #54
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: CI | |
on: # Trigger the workflow on push to main, pull request to main, or manual trigger | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
reserve-ci-instance: # Reserve an instance | |
runs-on: ubuntu-latest | |
outputs: | |
mpkit-url: ${{ steps.reserve.outputs.mpkit-url }} | |
report-path: ${{ steps.reserve.outputs.report-path }} | |
steps: | |
- name: Get ci-instance-url | |
id: reserve | |
uses: Platform-OS/[email protected] # Use our custom action to reserve an instance | |
with: | |
repository-url: ${{ vars.CI_REPOSITORY_URL }} | |
method: reserve | |
pos-ci-repo-token: ${{ secrets.POS_CI_REPO_ACCESS_TOKEN }} | |
deploy: | |
needs: ["reserve-ci-instance"] # Don't run this job until the reserve-ci-instance job is done | |
runs-on: ubuntu-latest | |
env: | |
MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }} | |
MPKIT_URL: ${{ needs.reserve-ci-instance.outputs.mpkit-url }} | |
POS_CI_REPO_ACCESS_TOKEN: ${{ secrets.POS_CI_REPO_ACCESS_TOKEN }} | |
CI: true | |
steps: | |
- name: get-mpkit-token | |
id: get-token | |
uses: Platform-OS/[email protected] # Use our custom action to reserve an instance | |
with: | |
method: get-token | |
repository-url: ${{ vars.CI_REPOSITORY_URL }} | |
pos-ci-repo-token: ${{ secrets.POS_CI_REPO_ACCESS_TOKEN }} | |
- name: use secret | |
env: | |
TOKEN: "${{ steps.get-token.outputs.mpkit-token }}" | |
run: | | |
echo hide-token | |
echo "::add-mask::$TOKEN" | |
echo "MPKIT_TOKEN=$TOKEN" >> $GITHUB_ENV | |
- name: Checkout your repository | |
uses: actions/checkout@v4 | |
- name: Install pos-cli | |
shell: sh | |
run: | | |
set -eu | |
npm install -g @platformos/pos-cli | |
- name: Deploy your project to the reserved instance | |
shell: sh | |
run: | | |
set -eu | |
pos-cli deploy | |
tests: | |
needs: ["reserve-ci-instance", "deploy"] # Don't run this job until both the reserve-ci-instance and deploy jobs are done | |
runs-on: ubuntu-latest | |
env: | |
MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }} | |
MPKIT_URL: ${{ needs.reserve-ci-instance.outputs.mpkit-url }} | |
REPORT_PATH: ${{ needs.reserve-ci-instance.outputs.report-path }} | |
UPLOAD_HOST: ${{ vars.TEST_REPORTS_UPLOAD_HOST }} | |
CI: true | |
steps: | |
- name: Checkout your repository | |
uses: actions/checkout@v4 | |
- name: Run unit tests | |
shell: sh | |
run: | | |
set -eu | |
npm run ci:test:unit | |
cleanup: | |
if: ${{ always() }} | |
needs: ["reserve-ci-instance", "deploy", "tests"] | |
runs-on: ubuntu-latest | |
steps: | |
- name: release ci-instance-url | |
uses: Platform-OS/[email protected] # Use our custom action to release the instance | |
with: | |
method: release | |
repository-url: ${{ vars.CI_REPOSITORY_URL }} | |
pos-ci-repo-token: ${{ secrets.POS_CI_REPO_ACCESS_TOKEN }} | |
# deploy-qa: # Deploy to QA on push to master and after tests pass | |
# if: ${{ github.ref_name == 'master' }} | |
# needs: ["tests"] # Don't run this job until the tests job is done and successful | |
# runs-on: ubuntu-latest | |
# env: | |
# MPKIT_EMAIL: ${{ secrets.MPKIT_EMAIL }} | |
# MPKIT_TOKEN: ${{ secrets.MPKIT_TOKEN }} | |
# MPKIT_URL: ${{ QA-HOST-URL }} | |
# POS_CI_REPO_ACCESS_TOKEN: ${{ secrets.POS_CI_REPO_ACCESS_TOKEN }} | |
# CI: true | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# | |
# - name: Build | |
# shell: sh | |
# run: | | |
# set -eu | |
# npm ci | |
# npm run build | |
# | |
# - name: Deploy | |
# shell: sh | |
# run: | | |
# set -eu | |
# pos-cli deploy |