Skip to content

Commit

Permalink
fix: set dev branch name by artifact sharing
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Sep 12, 2023
1 parent bc738d3 commit 9c86046
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
35 changes: 34 additions & 1 deletion .github/workflows/cd-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,43 @@ jobs:
url: https://api.development.basedosdados.org

steps:
- name: Download branch name
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "branch"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/artifact.zip`, Buffer.from(download.data));
- name: Extract branch name
run: unzip artifact.zip

- name: Read branch name
uses: actions/github-script@v6
id: extract_branch
with:
script: |
let fs = require('fs');
let branch = fs.readFileSync('./branch', 'utf8');
return branch;
- name: Checkout
uses: actions/checkout@v3
with:
ref: development
ref: ${{ steps.extract_branch.outputs.result }}

- name: Import secrets from Vault
id: import_secrets
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
types:
- labeled
workflow_dispatch:

jobs:
release-docker:
Expand Down Expand Up @@ -36,3 +37,15 @@ jobs:
org.opencontainers.image.revision=${{ github.sha }}
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Save branch name artifact
run: |
mkdir -p ./branch
echo -n ${{ github.event.pull_request.head.ref }} > ./branch/branch
- name: Upload branch name artifact
uses: actions/upload-artifact@v3
with:
name: branch
path: branch/
retention-days: 1

0 comments on commit 9c86046

Please sign in to comment.