Improve CI security. (#514) #2834
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: Platform | |
on: | |
push: | |
branches: | |
- main | |
- master | |
- release | |
- develop | |
env: | |
app: platform | |
GITHUB_TOKEN: ${{ secrets.REPOS_TOKEN }} | |
permissions: {} | |
jobs: | |
build-and-push: | |
permissions: | |
contents: read | |
runs-on: [self-hosted, common] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
persist-credentials: false | |
- name: Login to BIMData Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: docker-registry.bimdata.io | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_PASS }} | |
- id: tag | |
name: Get docker tag | |
uses: bimdata/actions/get-docker-tag@v2 | |
with: | |
branch: ${{ github.ref }} | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: etc/withprevious.Dockerfile | |
push: true | |
pull: true | |
build-args: | | |
PREVIOUS_TAG=${{ env.tag }} | |
tags: | | |
docker-registry.bimdata.io/bimdata/${{ env.app }}:${{ github.sha }} | |
docker-registry.bimdata.io/bimdata/${{ env.app }}:${{ env.tag }} | |
unit-tests: | |
permissions: | |
contents: read | |
runs-on: [self-hosted, common] | |
needs: build-and-push | |
if: ${{ !contains(github.event.head_commit.message, '[skip unit]') }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
persist-credentials: false | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- name: Run unit tests | |
run: npm install && npm run test:unit | |
e2e-tests: | |
runs-on: [self-hosted, testendtoend] | |
needs: build-and-push | |
if: ${{ !contains(github.event.head_commit.message, '[skip e2e]') && | |
github.ref != 'refs/heads/main' && | |
github.ref != 'refs/heads/master' && | |
github.ref != 'refs/heads/release' }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: bimdata/bimdata-test | |
ref: master | |
token: ${{ secrets.REPOS_TOKEN }} | |
persist-credentials: false | |
- id: tag | |
name: Get docker tag | |
uses: bimdata/actions/get-docker-tag@v2 | |
with: | |
branch: ${{ github.ref }} | |
- name: Run e2e tests | |
uses: ./end-to-end/ | |
with: | |
ref: ${{ github.ref }} | |
docker_tag: ${{ env.tag }} | |
github_token: ${{ secrets.REPOS_TOKEN }} | |
vault_passwd: ${{ secrets.VAULT_PASSWD }} | |
cypress_version: 13.16.0 | |
deploy: | |
runs-on: [self-hosted, common] | |
needs: build-and-push | |
steps: | |
- name: Login to BIMData Docker Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: docker-registry.bimdata.io | |
username: ${{ secrets.DOCKER_USER }} | |
password: ${{ secrets.DOCKER_PASS }} | |
- id: tag | |
name: Get docker tag | |
uses: bimdata/actions/get-docker-tag@v2 | |
with: | |
branch: ${{ github.ref }} | |
- name: Deploy on ${{ env.tag }} | |
uses: bimdata/actions/deployment@v2 | |
with: | |
inventory: ${{ env.tag }} | |
app: ${{ env.app }} | |
vault-pass: ${{ secrets.ANSIBLE_VAULT_PASSWD }} | |
release: | |
permissions: | |
contents: write # Required for creating tag / release | |
pull-requests: write # Required to add the comment on the PR to tell it's in the releases | |
issues: write # Required to add a comment to an issue fixed in a release | |
runs-on: [self-hosted, common] | |
needs: build-and-push | |
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
check-latest: true | |
- run: npm install -g npm@latest | |
- run: npm ci | |
- name: Release | |
run: npm run release |