Skip to content

Commit

Permalink
fix(cd): change ref on checkout when workflow_run
Browse files Browse the repository at this point in the history
  • Loading branch information
lsagetlethias committed Mar 23, 2022
1 parent 1360f7e commit 2036e2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -18,6 +18,7 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WIN_CSC_LINK: ${{ github.workspace }}/certwin.p12
CSC_LINK: ${{ github.workspace }}/certmac.p12
GITHUB_REF_OVERRIDE: ${{ github.event.workflow_run.conclusion == 'success' && format('refs/heads/{0}', github.event.workflow_run.head_branch) || github.ref }}

jobs:
compile:
Expand All @@ -34,6 +35,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.GITHUB_REF_OVERRIDE }}
- name: Decode certificates
env:
WIN_CSC_LINK_RAW: ${{ secrets.WIN_CSC_LINK }}
Expand Down Expand Up @@ -68,6 +70,9 @@ jobs:
name: Compile
run: |
export PATH="$(pwd)/.github/bin/:$PATH"
# override because of "env-ci" used by semantic-release
# GITHUB_REF should not be default branch when "workflow_run" event is triggered
export GITHUB_REF=$GITHUB_REF_OVERRIDE
echo ::set-output name=current-version::$(node -e "console.log(require('./package.json').version)")
yarn semantic-release
echo ::set-output name=next-version::$(node -e "console.log(require('./package.json').version)")
Expand Down Expand Up @@ -120,6 +125,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.GITHUB_REF_OVERRIDE }}
- name: Setup Node
uses: ./.github/actions/setup-node
- name: Yarn install
Expand Down Expand Up @@ -163,6 +169,7 @@ jobs:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.GITHUB_REF_OVERRIDE }}
- name: Download all dist form build jobs
uses: actions/download-artifact@v2
with:
Expand All @@ -189,4 +196,5 @@ jobs:
- name: Semantic Release
run: |
export PATH="$(pwd)/.github/bin/:$PATH"
export GITHUB_REF=$GITHUB_REF_OVERRIDE
yarn semantic-release
39 changes: 25 additions & 14 deletions .releaserc.js
Expand Up @@ -2,11 +2,33 @@
const releaseMode = process.env.ARCHIFILTRE_RELEASE_MODE ?? "normal";
const binName = require("./package.json").name;

console.info("Release script ----- Branch", process.env.GITHUB_REF);
console.info("Release script ----- Branch", {
originalRef: process.env.GITHUB_REF,
override: process.env.GITHUB_REF_OVERRIDE,
});
/** @type {import("semantic-release").Options["branches"]} */
const branches = [
"main",
{
channel: "next",
name: "dev",
prerelease: "next",
},
{
name: "beta",
prerelease: true,
},
];
const isPreRealse = process.env.GITHUB_REF
? ["refs/heads/dev", "refs/heads/beta"].includes(process.env.GITHUB_REF)
? branches.some(
(branche) =>
branche.prerelease &&
`refs/heads/${branche.name}` === process.env.GITHUB_REF
)
: true;

console.log({ isPreRealse });

/** @type {import("semantic-release").Options["plugins"]} */
const plugins = [
"@semantic-release/commit-analyzer",
Expand Down Expand Up @@ -66,18 +88,7 @@ if (releaseMode === "normal") {

/** @type {import("semantic-release").Options} */
const config = {
branches: [
"main",
{
channel: "next",
name: "dev",
prerelease: "next",
},
{
name: "beta",
prerelease: true,
},
],
branches,
plugins,
};

Expand Down

0 comments on commit 2036e2c

Please sign in to comment.