|
| 1 | +name: Publish new build |
| 2 | +run-name: "Publish new images for ${{ github.ref_name }} triggered by ${{ github.actor }}; version: ${{ inputs.version || 'N/A'}}" |
| 3 | + |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + types: [opened, synchronize] |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + version: |
| 13 | + description: "Enter the version number" |
| 14 | + required: true |
| 15 | + deploy-to-production: |
| 16 | + description: "Deploy the new version on production?" |
| 17 | + required: false |
| 18 | + type: boolean |
| 19 | + default: false |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + code-check: |
| 26 | + uses: ./.github/workflows/code-check.yml |
| 27 | + |
| 28 | + bump-version: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + if: ${{ github.ref_name == 'main' && inputs.version != '' }} |
| 31 | + needs: |
| 32 | + - code-check |
| 33 | + outputs: |
| 34 | + commit_sha: ${{ steps.commit-version.outputs.commit_sha }} |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout code |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Install semver |
| 41 | + run: npm install semver |
| 42 | + |
| 43 | + - name: Get current version |
| 44 | + run: echo "current_version=$(jq -r '.version' package.json)" >> $GITHUB_ENV |
| 45 | + |
| 46 | + - name: Validate and set new version |
| 47 | + run: | |
| 48 | + new_version="${{ inputs.version }}" |
| 49 | + current_version="${{ env.current_version }}" |
| 50 | +
|
| 51 | + if npx semver $new_version -r "<=$current_version"; then |
| 52 | + echo "Error: New version ($new_version) is lowest or the same as current ($current_version)" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Bump version |
| 57 | + run: | |
| 58 | + npm version ${{ inputs.version }} --no-git-tag-version |
| 59 | +
|
| 60 | + - name: Git config |
| 61 | + run: | |
| 62 | + git config user.name "${GITHUB_ACTOR}" |
| 63 | + git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" |
| 64 | +
|
| 65 | + - name: Commit version change |
| 66 | + id: commit-version |
| 67 | + run: | |
| 68 | + git commit -am "Update version to ${{ inputs.version }}" |
| 69 | + git push origin main |
| 70 | + echo "commit_sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
| 71 | +
|
| 72 | + build-and-publish: |
| 73 | + needs: |
| 74 | + - code-check |
| 75 | + - bump-version |
| 76 | + if: | |
| 77 | + always() && |
| 78 | + !contains(needs.*.result, 'failure') && |
| 79 | + !contains(needs.*.result, 'cancelled') |
| 80 | + uses: ./.github/workflows/build-docker-image.yml |
| 81 | + with: |
| 82 | + version: ${{ inputs.version }} |
| 83 | + commit_sha: ${{ github.ref_name == 'main' && inputs.version != '' && needs.bump-version.outputs.commit_sha || '' }} |
| 84 | + secrets: inherit |
| 85 | + |
| 86 | + git-tag: |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: |
| 89 | + - bump-version |
| 90 | + - build-and-publish |
| 91 | + if: | |
| 92 | + ${{ github.ref_name == 'main' && inputs.version != '' }} && |
| 93 | + always() && |
| 94 | + !contains(needs.*.result, 'failure') && |
| 95 | + !contains(needs.*.result, 'cancelled') |
| 96 | + steps: |
| 97 | + - name: Checkout code |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + ref: ${{ needs.bump-version.outputs.commit_sha }} |
| 101 | + |
| 102 | + - name: Create and push tag |
| 103 | + run: | |
| 104 | + TAG_NAME="v${{ inputs.version }}" |
| 105 | + git tag $TAG_NAME |
| 106 | + git push origin $TAG_NAME |
| 107 | +
|
| 108 | + trigger-production-deploy: |
| 109 | + runs-on: ubuntu-latest |
| 110 | + needs: |
| 111 | + - code-check |
| 112 | + - build-and-publish |
| 113 | + if: ${{ inputs.version != '' && inputs.deploy-to-production == true }} |
| 114 | + environment: production-fidl |
| 115 | + steps: |
| 116 | + - name: Trigger production deploy |
| 117 | + uses: neti-filplus-infra/filplus-deploy-action@main |
| 118 | + with: |
| 119 | + version: ${{ inputs.version }} |
| 120 | + environment: production |
| 121 | + ecr-repository: filecoin-oracle-service |
| 122 | + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_IMAGE_DEPLOYER }} |
| 123 | + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_IMAGE_DEPLOYER }} |
| 124 | + aws-region: us-east-1 |
0 commit comments