Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 3c6fb18

Browse files
authored
github: fix workflow permissions error (#58)
currently, the publish job, although not used at all by the release workflow, is imported as part of the build.yaml import (for the side effect of importing lint, tests and build jobs). however, this is causing an issue since we switched the default permissions to contents/packages read instead of write. as the publish job requires the write permission, however, build.yaml is imported with the standard permissions, causing the following error: The workflow is not valid. .github/workflows/release.yml (Line: 9, Col: 3): Error calling workflow 'DataDog/otel-profiling-agent/.github/workflows/build.yml@5d1ecca'. The nested job 'publish' is requesting 'contents: write, packages: write', but is only allowed 'contents: read, packages: read'. To fix this, we create a new workflow, pre-release, that contains the publish job, this way common build, lint, tests jobs can be imported by both release and pre-release without causing any issue
1 parent 5d1ecca commit 3c6fb18

File tree

2 files changed

+63
-55
lines changed

2 files changed

+63
-55
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
name: CI
1+
name: Common build
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
types: [opened, synchronize, reopened, labeled]
8-
branches: ["**"]
94
workflow_call:
105

116
jobs:
@@ -244,52 +239,3 @@ jobs:
244239
with:
245240
name: agent-${{ matrix.os == 'arm-4core-linux-ubuntu24.04' && 'aarch64' || 'x86_64' }}
246241
path: otel-profiling-agent
247-
248-
publish:
249-
env:
250-
RELEASE_VERSION: ${{ github.event_name == 'pull_request' && 'dev-test' || 'dev' }}
251-
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'publish-dev-test') )}}
252-
name: Publish pre-release
253-
needs: [build]
254-
runs-on: ubuntu-24.04
255-
permissions:
256-
contents: write
257-
packages: write
258-
steps:
259-
- name: Download artifacts
260-
uses: actions/download-artifact@v4
261-
- name: Create assets
262-
run: |
263-
tar czf otel-profiling-agent-${RELEASE_VERSION}-aarch64.tar.gz -C agent-aarch64 .
264-
tar czf otel-profiling-agent-${RELEASE_VERSION}-x86_64.tar.gz -C agent-x86_64 .
265-
sha256sum otel-profiling-agent-${RELEASE_VERSION}-aarch64.tar.gz otel-profiling-agent-${RELEASE_VERSION}-x86_64.tar.gz > sha256sums.txt
266-
- name: Create or move previous dev tag
267-
continue-on-error: true
268-
uses: actions/github-script@v7
269-
with:
270-
script: |
271-
github.rest.git.createRef({
272-
owner: context.repo.owner,
273-
repo: context.repo.repo,
274-
ref: 'refs/tags/${{ env.RELEASE_VERSION }}',
275-
sha: context.sha
276-
}).catch(err => {
277-
if (err.status !== 422) throw err;
278-
github.rest.git.updateRef({
279-
owner: context.repo.owner,
280-
repo: context.repo.repo,
281-
ref: 'tags/${{ env.RELEASE_VERSION }}',
282-
sha: context.sha
283-
})
284-
});
285-
- name: Create pre-release
286-
uses: ncipollo/release-action@v1
287-
with:
288-
artifacts: "otel-profiling-agent-${{ env.RELEASE_VERSION }}-*.tar.gz,sha256sums.txt"
289-
allowUpdates: true
290-
removeArtifacts: true
291-
omitBody: true
292-
omitDraftDuringUpdate: true
293-
prerelease: true
294-
draft: false
295-
tag: ${{ env.RELEASE_VERSION }}

.github/workflows/pre-release.yaml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
types: [opened, synchronize, reopened, labeled]
8+
branches: ["**"]
9+
10+
jobs:
11+
build:
12+
name: Build
13+
uses: ./.github/workflows/build.yml
14+
15+
publish:
16+
env:
17+
RELEASE_VERSION: ${{ github.event_name == 'pull_request' && 'dev-test' || 'dev' }}
18+
if: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') || (github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'publish-dev-test') )}}
19+
name: Publish pre-release
20+
needs: [build]
21+
runs-on: ubuntu-24.04
22+
permissions:
23+
contents: write
24+
packages: write
25+
steps:
26+
- name: Download artifacts
27+
uses: actions/download-artifact@v4
28+
- name: Create assets
29+
run: |
30+
tar czf otel-profiling-agent-${RELEASE_VERSION}-aarch64.tar.gz -C agent-aarch64 .
31+
tar czf otel-profiling-agent-${RELEASE_VERSION}-x86_64.tar.gz -C agent-x86_64 .
32+
sha256sum otel-profiling-agent-${RELEASE_VERSION}-aarch64.tar.gz otel-profiling-agent-${RELEASE_VERSION}-x86_64.tar.gz > sha256sums.txt
33+
- name: Create or move previous dev tag
34+
continue-on-error: true
35+
uses: actions/github-script@v7
36+
with:
37+
script: |
38+
github.rest.git.createRef({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
ref: 'refs/tags/${{ env.RELEASE_VERSION }}',
42+
sha: context.sha
43+
}).catch(err => {
44+
if (err.status !== 422) throw err;
45+
github.rest.git.updateRef({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
ref: 'tags/${{ env.RELEASE_VERSION }}',
49+
sha: context.sha
50+
})
51+
});
52+
- name: Create pre-release
53+
uses: ncipollo/release-action@v1
54+
with:
55+
artifacts: "otel-profiling-agent-${{ env.RELEASE_VERSION }}-*.tar.gz,sha256sums.txt"
56+
allowUpdates: true
57+
removeArtifacts: true
58+
omitBody: true
59+
omitDraftDuringUpdate: true
60+
prerelease: true
61+
draft: false
62+
tag: ${{ env.RELEASE_VERSION }}

0 commit comments

Comments
 (0)