|
| 1 | +name: Build Certbot Lambda Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + setup-build-workflow: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + outputs: |
| 15 | + IS_PRERELEASE: ${{ steps.set-vars.outputs.IS_PRERELEASE }} |
| 16 | + IS_MERGE_TO_MAIN: ${{ steps.set-vars.outputs.IS_MERGE_TO_MAIN }} |
| 17 | + IS_MERGE_TO_DEVELOP: ${{ steps.set-vars.outputs.IS_MERGE_TO_DEVELOP }} |
| 18 | + REF_TO_BUILD_AND_TAG: ${{ steps.set-vars.outputs.REF_TO_BUILD_AND_TAG }} |
| 19 | + IS_DEPENDABOT_PR: ${{ steps.actor_check.outputs.IS_DEPENDABOT_PR }} |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Set default env variables |
| 23 | + id: set-vars |
| 24 | + uses: actions/github-script@v7 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const targetRef = '${{ github.base_ref }}'; |
| 28 | + const sourceRef = '${{ github.head_ref }}'; |
| 29 | + const mergeRef = '${{ github.ref }}'; |
| 30 | +
|
| 31 | + const prIsDraft = '${{ github.event.pull_request.draft }}' === 'true'; |
| 32 | + const prMergedToMain = mergeRef === 'refs/heads/master'; |
| 33 | +
|
| 34 | + const isPreRelease = !prMergedToMain |
| 35 | +
|
| 36 | + // For a detailed explanation of why we use different refs for different scenarios |
| 37 | + // see https://docs.github.com/en/rest/reference/pulls#get-a-pull-request |
| 38 | + const refToBuildAndTag = isPreRelease ? sourceRef : mergeRef; |
| 39 | +
|
| 40 | + Object.entries({ |
| 41 | + IS_PRERELEASE: isPreRelease, |
| 42 | + IS_MERGE_TO_MAIN: prMergedToMain, |
| 43 | + REF_TO_BUILD_AND_TAG: refToBuildAndTag, |
| 44 | + }).forEach(pair => { |
| 45 | + core.setOutput(...pair); |
| 46 | + console.info(...pair); |
| 47 | + }); |
| 48 | +
|
| 49 | + - name: Check if Dependabot PR |
| 50 | + id: actor_check |
| 51 | + uses: actions/github-script@v7 |
| 52 | + with: |
| 53 | + script: | |
| 54 | + const actor = '${{ github.actor}}'; |
| 55 | + const knownDependabotNames = [ |
| 56 | + 'dependabot[bot]', |
| 57 | + 'dependabot' |
| 58 | + ]; |
| 59 | + const isDependabotPR = knownDependabotNames.includes(actor); |
| 60 | + core.info(`Is Dependabot PR: ${isDependabotPR}`); |
| 61 | + core.setOutput('IS_DEPENDABOT_PR', isDependabotPR); |
| 62 | +
|
| 63 | + get-version: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: setup-build-workflow |
| 66 | + |
| 67 | + outputs: |
| 68 | + NEXT_VERSION: ${{ steps.get-version.outputs.NEXT_VERSION }} |
| 69 | + NEXT_VERSION_NO_PREFIX: ${{ steps.get-version.outputs.NEXT_VERSION_NO_PREFIX }} |
| 70 | + |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v5 |
| 73 | + with: |
| 74 | + fetch-depth: 0 # Includes all history for all branches and tags |
| 75 | + |
| 76 | + - id: get-version |
| 77 | + uses: joemcbride/[email protected] |
| 78 | + with: |
| 79 | + calculate-prerelease-version: ${{ needs.setup-build-workflow.outputs.IS_PRERELEASE }} |
| 80 | + branch-name: ${{ needs.setup-build-workflow.outputs.REF_TO_BUILD_AND_TAG }} |
| 81 | + tag-prefix: certbot- |
| 82 | + fallback-to-no-prefix-search: false |
| 83 | + default-release-type: minor |
| 84 | + create-ref: true |
| 85 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 86 | + |
| 87 | + - run: | |
| 88 | + echo "The next version is ${{ env.NEXT_VERSION }}" |
| 89 | + echo "The next version without the prefix is ${{ env.NEXT_VERSION_NO_PREFIX }}" |
| 90 | + |
| 91 | + build: |
| 92 | + runs-on: ubuntu-latest |
| 93 | + needs: get-version |
| 94 | + permissions: |
| 95 | + id-token: write |
| 96 | + contents: read |
| 97 | + env: |
| 98 | + CI: true |
| 99 | + AWS_REGION: us-west-2 |
| 100 | + NEXT_VERSION: ${{ needs.get-version.outputs.NEXT_VERSION }} |
| 101 | + NEXT_VERSION_NO_PREFIX: ${{ needs.get-version.outputs.NEXT_VERSION_NO_PREFIX }} |
| 102 | + NEXT_BUILD_VERSION: ${{ needs.get-version.outputs.NEXT_BUILD_VERSION }} |
| 103 | + |
| 104 | + steps: |
| 105 | + - name: Checkout code |
| 106 | + uses: actions/checkout@v5 |
| 107 | + |
| 108 | + - name: Set up Python |
| 109 | + uses: actions/setup-python@v6 |
| 110 | + with: |
| 111 | + python-version: '3.13' |
| 112 | + |
| 113 | + - name: Run package script |
| 114 | + run: ./package.sh |
| 115 | + |
| 116 | + - name: Show package size |
| 117 | + run: | |
| 118 | + echo "Package size:" |
| 119 | + du -h certbot/certbot-lambda.zip || echo "certbot-lambda.zip not found" |
| 120 | + |
| 121 | + - name: Upload build artifacts |
| 122 | + uses: actions/upload-artifact@v4 |
| 123 | + with: |
| 124 | + name: certbot-lambda-package |
| 125 | + path: certbot/certbot-lambda.zip |
| 126 | + retention-days: 30 |
| 127 | + |
| 128 | + - name: Configure AWS Credentials |
| 129 | + uses: aws-actions/configure-aws-credentials@v5 |
| 130 | + with: |
| 131 | + role-to-assume: arn:aws:iam::888985673581:role/GithubActions-DovetailSofware_Org-OIDC |
| 132 | + role-session-name: GitHub_to_AWS_via_FederatedOIDC |
| 133 | + aws-region: ${{ env.AWS_REGION }} |
| 134 | + |
| 135 | + - name: Upload Certbot Lambda Assets to S3 |
| 136 | + working-directory: certbot |
| 137 | + run: | |
| 138 | + aws s3 cp . s3://jenkins-artifacts.us-west-2.dovetailnow.com/jobs/certbot-lambda/$NEXT_VERSION_NO_PREFIX --recursive --exclude "*" --include "*.zip" |
0 commit comments