Skip to content

Commit 84688df

Browse files
v1vxrmx
andauthored
ci: run the release when merges to main (#1998)
* ci: run the release when merges to main * avoid wrong docker-tag name * use the opposite * fix yaml * enable test, slack message conditional and fix names * Update .github/workflows/release.yml * skip test for branches in the release workflow * workaround * fix * Update .github/workflows/release.yml * support releases in test.pypi for commits on main * set environment variable in the reusable workflow instead env propagation between reusable workflow is not supported * setup: take a post version from environment variable * Update .github/workflows/release.yml --------- Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent a982eb8 commit 84688df

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

.github/workflows/packages.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
- '**/*.md'
1414
- '**/*.asciidoc'
1515

16+
# Override the version if there is no tag release.
17+
env:
18+
ELASTIC_CI_POST_VERSION: ${{ startsWith(github.ref, 'refs/tags') && '' || github.run_id }}
19+
1620
jobs:
1721
build:
1822
runs-on: ubuntu-latest

.github/workflows/release.yml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ on:
44
push:
55
tags:
66
- "v*.*.*"
7+
branches:
8+
- main
79

810
permissions:
911
contents: read
1012

1113
jobs:
1214
test:
13-
uses: ./.github/workflows/test.yml
15+
uses: ./.github/workflows/test-release.yml
1416
with:
1517
full-matrix: true
18+
enabled: ${{ startsWith(github.ref, 'refs/tags') }}
1619

1720
packages:
1821
uses: ./.github/workflows/packages.yml
@@ -31,10 +34,16 @@ jobs:
3134
with:
3235
name: packages
3336
path: dist
34-
- name: Upload
37+
- name: Upload pypi.org
38+
if: startsWith(github.ref, 'refs/tags')
3539
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
3640
with:
3741
repository-url: https://upload.pypi.org/legacy/
42+
- name: Upload test.pypi.org
43+
if: ${{ ! startsWith(github.ref, 'refs/tags') }}
44+
uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
45+
with:
46+
repository-url: https://test.pypi.org/legacy/
3847

3948
build-distribution:
4049
uses: ./.github/workflows/build-distribution.yml
@@ -59,13 +68,15 @@ jobs:
5968
name: build-distribution
6069
path: ./build
6170
- name: Publish lambda layers to AWS
71+
if: startsWith(github.ref, 'refs/tags')
6272
run: |
6373
# Convert v1.2.3 to ver-1-2-3
6474
VERSION=${GITHUB_REF_NAME/v/ver-}
6575
VERSION=${VERSION//./-}
6676
6777
ELASTIC_LAYER_NAME="elastic-apm-python-${VERSION}" .ci/publish-aws.sh
6878
- uses: actions/upload-artifact@v4
79+
if: startsWith(github.ref, 'refs/tags')
6980
with:
7081
name: arn-file
7182
path: ".arn-file.md"
@@ -75,6 +86,8 @@ jobs:
7586
needs:
7687
- build-distribution
7788
runs-on: ubuntu-latest
89+
env:
90+
DOCKER_IMAGE_NAME: docker.elastic.co/observability/apm-agent-python
7891
steps:
7992
- uses: actions/checkout@v4
8093
- uses: elastic/apm-pipeline-library/.github/actions/docker-login@current
@@ -91,30 +104,35 @@ jobs:
91104
- id: setup-docker
92105
name: Set up docker variables
93106
run: |-
94-
# version without v prefix (e.g. 1.2.3)
95-
echo "tag=${GITHUB_REF_NAME/v/}" >> "${GITHUB_OUTPUT}"
96-
echo "name=docker.elastic.co/observability/apm-agent-python" >> "${GITHUB_OUTPUT}"
107+
if [ "${{ startsWith(github.ref, 'refs/tags') }}" == "false" ] ; then
108+
# for testing purposes
109+
echo "tag=test" >> "${GITHUB_OUTPUT}"
110+
else
111+
# version without v prefix (e.g. 1.2.3)
112+
echo "tag=${GITHUB_REF_NAME/v/}" >> "${GITHUB_OUTPUT}"
113+
fi
97114
- name: Docker build
98115
run: >-
99116
docker build
100-
-t ${{ steps.setup-docker.outputs.name }}:${{ steps.setup-docker.outputs.tag }}
117+
-t ${{ env.DOCKER_IMAGE_NAME }}:${{ steps.setup-docker.outputs.tag }}
101118
--build-arg AGENT_DIR=./build/dist/package/python
102119
.
103120
- name: Docker retag
104121
run: >-
105122
docker tag
106-
${{ steps.setup-docker.outputs.name }}:${{ steps.setup-docker.outputs.tag }}
107-
${{ steps.setup-docker.outputs.name }}:latest
123+
${{ env.DOCKER_IMAGE_NAME }}:${{ steps.setup-docker.outputs.tag }}
124+
${{ env.DOCKER_IMAGE_NAME }}:latest
108125
- name: Docker push
126+
if: startsWith(github.ref, 'refs/tags')
109127
run: |-
110-
docker push ${{ steps.setup-docker.outputs.name }}:${{ steps.setup-docker.outputs.tag }}
111-
docker push ${{ steps.setup-docker.outputs.name }}:latest
128+
docker push --all-tags ${{ env.DOCKER_IMAGE_NAME }}
112129
113130
github-draft:
114131
permissions:
115132
contents: write
116133
needs:
117134
- publish-lambda-layers
135+
if: startsWith(github.ref, 'refs/tags')
118136
runs-on: ubuntu-latest
119137
steps:
120138
- uses: actions/checkout@v4
@@ -145,6 +163,7 @@ jobs:
145163
with:
146164
needs: ${{ toJSON(needs) }}
147165
- uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
166+
if: startsWith(github.ref, 'refs/tags')
148167
with:
149168
status: ${{ steps.check.outputs.status }}
150169
vaultUrl: ${{ secrets.VAULT_ADDR }}

.github/workflows/test-release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: test-release
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
full-matrix:
7+
description: "Run the full matrix"
8+
required: true
9+
type: boolean
10+
ref:
11+
description: "The git ref of elastic/apm-agent-python to run test workflow from."
12+
required: false
13+
type: string
14+
enabled:
15+
description: "Whether to run the workfow"
16+
required: true
17+
type: boolean
18+
workflow_dispatch:
19+
inputs:
20+
full-matrix:
21+
description: "Run the full matrix"
22+
required: true
23+
type: boolean
24+
enabled:
25+
description: "Whether to run the workfow"
26+
required: true
27+
type: boolean
28+
29+
jobs:
30+
test:
31+
if: ${{ inputs.enabled }}
32+
uses: ./.github/workflows/test.yml
33+
with:
34+
full-matrix: ${{ inputs.full-matrix }}
35+
36+
run-if-disabled:
37+
if: ${{ ! inputs.enabled }}
38+
runs-on: ubuntu-latest
39+
steps:
40+
- run: echo "do something to help with the reusable workflows with needs"

0 commit comments

Comments
 (0)