|
| 1 | +name: Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths-ignore: |
| 6 | + - '**.md' |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + - release/** |
| 11 | + paths-ignore: |
| 12 | + - '**.md' |
| 13 | + |
| 14 | +env: |
| 15 | + # Variables defined in the repository |
| 16 | + SENTRY_ORG: ${{ vars.SENTRY_ORG }} |
| 17 | + # For master, we have an environment variable that selects the action-release project |
| 18 | + # instead of action-release-prs |
| 19 | + # For other branches: https://sentry-ecosystem.sentry.io/releases/?project=4505075304693760 |
| 20 | + # For master branch: https://sentry-ecosystem.sentry.io/releases/?project=6576594 |
| 21 | + SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} |
| 22 | + |
| 23 | +jobs: |
| 24 | + docker-build: |
| 25 | + name: Build & publish Docker images |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + packages: write |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + target: |
| 32 | + - name: builder |
| 33 | + image: action-release-builder-image |
| 34 | + - name: app |
| 35 | + image: action-release-image |
| 36 | + steps: |
| 37 | + - name: Checkout repo |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Evaluate docker tag |
| 43 | + run: | |
| 44 | + if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then |
| 45 | + echo "DOCKER_TAG=master" >> $GITHUB_ENV |
| 46 | + yarn set-docker-tag master |
| 47 | +
|
| 48 | + if ! git diff --quiet action.yml; then |
| 49 | + echo "GIT_COMMITTER_NAME=getsentry-bot" >> $GITHUB_ENV; |
| 50 | + echo "GIT_AUTHOR_NAME=getsentry-bot" >> $GITHUB_ENV; |
| 51 | + echo "[email protected]" >> $GITHUB_ENV; |
| 52 | +
|
| 53 | + git add action.yml |
| 54 | + SKIP=lint,format,set-docker-tag-from-branch git commit -m "chore: Set docker tag for master [skip-ci]" |
| 55 | + git push |
| 56 | + fi |
| 57 | + else |
| 58 | + TAG=$(yq '... | select(has("uses") and .uses | test("docker://ghcr.io/getsentry/action-release-image:.*")) | .uses' action.yml | awk -F':' '{print $3}') |
| 59 | + echo "DOCKER_TAG=$TAG" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + if [[ "${{ github.event_name }}" == "pull_request" ]]; then |
| 62 | + if [[ "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 63 | + echo "Error: DOCKER_TAG $TAG matching format MAJOR.MINOR.PATCH is not allowed inside pull requests." |
| 64 | + echo "Please rename the docker tag in action.yml and try again." |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + fi |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Set up QEMU |
| 71 | + uses: docker/setup-qemu-action@v3 |
| 72 | + |
| 73 | + - name: Set up Docker Buildx |
| 74 | + uses: docker/setup-buildx-action@v3 |
| 75 | + |
| 76 | + - name: Login to GitHub Container Registry |
| 77 | + uses: docker/login-action@v3 |
| 78 | + with: |
| 79 | + registry: ghcr.io |
| 80 | + username: ${{ github.actor }} |
| 81 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + |
| 83 | + # BUILDKIT_INLINE_CACHE creates the image in such a way that you can |
| 84 | + # then use --cache-from (think of a remote cache) |
| 85 | + # This feature is allowed thanks to using the buildx plugin |
| 86 | + # |
| 87 | + # There's a COPY command in the builder stage that can easily invalidate the cache |
| 88 | + # If you notice, please add more exceptions to .dockerignore since we loose the value |
| 89 | + # of using --cache-from on the app stage |
| 90 | + - name: Build and push |
| 91 | + uses: docker/build-push-action@v6 |
| 92 | + with: |
| 93 | + platforms: linux/amd64,linux/arm64 |
| 94 | + push: true |
| 95 | + tags: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:${{ env.DOCKER_TAG }} |
| 96 | + cache-from: ghcr.io/${{ github.repository_owner }}/${{ matrix.target.image }}:master |
| 97 | + target: ${{ matrix.target.name }} |
| 98 | + build-args: BUILDKIT_INLINE_CACHE=1 |
| 99 | + |
| 100 | + lint: |
| 101 | + runs-on: ubuntu-latest |
| 102 | + |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + |
| 106 | + - name: Install |
| 107 | + run: yarn install |
| 108 | + |
| 109 | + - name: Check format |
| 110 | + run: yarn format-check |
| 111 | + |
| 112 | + - name: Lint |
| 113 | + run: yarn lint |
| 114 | + |
| 115 | + - name: Build |
| 116 | + run: yarn build |
| 117 | + |
| 118 | + ############# |
| 119 | + # E2E Tests |
| 120 | + ############# |
| 121 | + |
| 122 | + test-create-staging-release-per-push: |
| 123 | + needs: docker-build |
| 124 | + strategy: |
| 125 | + matrix: |
| 126 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 127 | + runs-on: ${{ matrix.os }} |
| 128 | + name: Test current action |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + with: |
| 132 | + fetch-depth: 0 |
| 133 | + |
| 134 | + - name: Create a staging release |
| 135 | + uses: ./ |
| 136 | + env: |
| 137 | + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
| 138 | + SENTRY_LOG_LEVEL: debug |
| 139 | + with: |
| 140 | + ignore_missing: true |
| 141 | + |
| 142 | + test-runs-on-container: |
| 143 | + needs: docker-build |
| 144 | + runs-on: ubuntu-latest |
| 145 | + container: |
| 146 | + image: node:18.17 |
| 147 | + |
| 148 | + steps: |
| 149 | + - uses: actions/checkout@v4 |
| 150 | + with: |
| 151 | + fetch-depth: 0 |
| 152 | + |
| 153 | + - name: Create a staging release |
| 154 | + uses: ./ |
| 155 | + env: |
| 156 | + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} |
| 157 | + SENTRY_LOG_LEVEL: debug |
| 158 | + with: |
| 159 | + ignore_missing: true |
| 160 | + |
| 161 | + test-mock-release: |
| 162 | + needs: docker-build |
| 163 | + strategy: |
| 164 | + matrix: |
| 165 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 166 | + runs-on: ${{ matrix.os }} |
| 167 | + name: Mock a release |
| 168 | + steps: |
| 169 | + - uses: actions/checkout@v4 |
| 170 | + with: |
| 171 | + fetch-depth: 0 |
| 172 | + |
| 173 | + - name: Mock creating a Sentry release |
| 174 | + uses: ./ |
| 175 | + env: |
| 176 | + MOCK: true |
| 177 | + with: |
| 178 | + environment: production |
| 179 | + |
| 180 | + test-mock-release-working-directory: |
| 181 | + needs: docker-build |
| 182 | + strategy: |
| 183 | + matrix: |
| 184 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 185 | + runs-on: ${{ matrix.os }} |
| 186 | + name: Mock a release in a different working directory |
| 187 | + steps: |
| 188 | + - name: Checkout directory we'll be running from |
| 189 | + uses: actions/checkout@v4 |
| 190 | + with: |
| 191 | + fetch-depth: 0 |
| 192 | + path: main/ |
| 193 | + |
| 194 | + - name: Checkout directory we'll be testing |
| 195 | + uses: actions/checkout@v4 |
| 196 | + with: |
| 197 | + fetch-depth: 0 |
| 198 | + path: test/ |
| 199 | + |
| 200 | + - name: Mock creating a Sentry release in a different directory |
| 201 | + uses: ./main |
| 202 | + env: |
| 203 | + MOCK: true |
| 204 | + with: |
| 205 | + environment: production |
| 206 | + working_directory: ./test |
0 commit comments